// Inicio Funcion Abrir void abrir() { int iResp; String strTexto = null; Vector<String> alLinea = null; Archivo leerArchivo = null; try { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileFilter(filter); fileChooser.setDialogTitle("Abrir Archivo"); iResp = fileChooser.showOpenDialog(fileChooser); if (iResp == JFileChooser.OPEN_DIALOG) { leerArchivo = new Archivo(); alLinea = leerArchivo.LeeArchivo(fileChooser.getSelectedFile().toString()); RutaOpen = fileChooser.getSelectedFile().toString(); if (alLinea.size() > 0) { textArea.setText(""); for (int iIndice = 0; iIndice < alLinea.size(); iIndice++) { strTexto = (String) alLinea.get(iIndice); textArea.append(strTexto + "\n"); } } } } catch (NumberFormatException ex) { System.out.println(ex.getMessage()); } }
// Inicio Función Guardar void Guardar() { if (RutaOpen != null) { Archivo guardar = new Archivo(); String txta = textArea.getText(); RutaOpen = guardar.GuardaArchivo(txta, fc, RutaOpen); } else { GuardarComo(); } }
// inicio Impresion void imprimir() { int nlinea = 1; String lst = ""; for (int i = 0; i < lista.size(); i++, nlinea++) { System.out.println("\n*Linea " + nlinea); lst += lista.get(i).imprimirVector(nlinea) + "\n"; } System.out.println("\n\n" + lst); Archivo guardar = new Archivo(); RutaOpen = guardar.GuardaArchivo(lst, fc, "Prueba.lst"); }
// Inicio Funcion GuardarComo void GuardarComo() { fc.setDialogTitle("Guardar Archivo"); int returnVal = fc.showSaveDialog(Frame.this); if (returnVal == JFileChooser.APPROVE_OPTION) { String txta = textArea.getText(); Archivo gcomo = new Archivo(); RutaOpen = gcomo.GuardaArchivo(txta, fc, RutaOpen); } else { JOptionPane.showMessageDialog(null, "Cancelado"); } }
/** * Crea el fichero de indices con la informacion inicial necesaria para un archivo concreto. * * @param fichero es el fichero de indices que tendra toda la informacion. * @param archivo es el objeto que representa el archivo en concreto. * @param fragmentos es la lista de fragmentos que faltan de dicho archivo. */ public void crearFicheroIndices(File fichero, Archivo archivo, Vector<Fragmento> fragmentos) { Vector<Fragmento> fragTengo = new Vector<Fragmento>(), fragFaltan = fragmentos; Indices indices = new Indices(archivo, fragTengo, fragFaltan); ByteArrayOutputStream bs = new ByteArrayOutputStream(); try { ObjectOutputStream os = new ObjectOutputStream(bs); os.writeObject(indices); os.close(); } catch (IOException e) { /*System.out.println("Error -> posibles causas: "); System.out.println( "\tProblemas al crear un flujo de bytes serializable" ); System.out.println( "\tProblemas al serializar el objeto indice" ); System.out.println( "\tProblemas al cerrar el flujo serializable" );*/ ControlDeErrores.getInstancia() .registrarError( ErrorEGorilla.ERROR_DISCO, "Error -> posibles causas: " + "\tProblemas al crear un flujo de bytes serializable" + "\tProblemas al serializar el objeto indice" + "\tProblemas al cerrar el flujo serializable"); // e.printStackTrace(); } byte[] bytes = bs.toByteArray(); // devuelve byte[] try { if (fichero.exists() == true) { String nombreNuevoFichero = fichero.getName(); nombreNuevoFichero += "_" + archivo.getHash(); fichero = new File(nombreNuevoFichero); } FileOutputStream ficheroIndices = new FileOutputStream(fichero); BufferedOutputStream bufferedOutput = new BufferedOutputStream(ficheroIndices); bufferedOutput.write(bytes, 0, bytes.length); bufferedOutput.close(); // creo que tambien hace falta cerrar el otro ficheroIndices.close(); } catch (FileNotFoundException e) { System.out.println("No existe el fichero <" + fichero.getName() + ">"); } catch (IOException e) { /*System.out.println("Error -> posibles causas: "); System.out.println( "\tProblemas al escribir en el fichero <"+fichero.getName()+">" ); System.out.println( "\tProblemas al cerrar el flujo o el fichero <"+fichero.getName()+">" );*/ ControlDeErrores.getInstancia() .registrarError( ErrorEGorilla.ERROR_DISCO, "Error -> posibles causas: " + "\tProblemas al escribir en el fichero <" + fichero.getName() + ">" + "\tProblemas al cerrar el flujo o el fichero <" + fichero.getName() + ">"); // e.printStackTrace(); } }
@Override public void actionPerformed(ActionEvent e) { if (e.getSource() == jbtnLoad) { ruta = archivo.abrirRuta(); if (validar.validarAsm(ruta)) { jtxtAsm.setText(""); jtxtInst.setText(""); try { textoAsm = archivo.leerArchivo(ruta); jtxtAsm.setText(textoAsm); estado = 1; } catch (IOException a) { } } else { JOptionPane.showMessageDialog( null, "El archivo seleccionado no tiene la extensión correcta (asm)"); } } else if (e.getSource() == jbtnProcess) { if (estado > 0) { boolean endCODOP = false; arregloLineas = procesos.separaLineas(textoAsm); archivo.crearArchivos("inst", "#\tETQ\tCODOP\tOper\r\n"); archivo.crearArchivos("err", "#\tCodigo\t\t|Error\r\n"); for (i = 0; i < procesos.lineasAsm; i++) { if (arregloLineas[i].matches("^\\s*$")) continue; procesos.combinacion = validar.validarLinea(arregloLineas[i]); if (procesos.combinacion == 0) { linea = procesos.escribirError(arregloLineas[i].trim(), validar.mensaje, i + 1); archivo.escribirErr(linea); } else { linea = procesos.escribirLinea(arregloLineas[i].trim(), i + 1); archivo.escribirInst(linea); } if (procesos.codop.matches("^[eE][nN][dD]$")) { endCODOP = true; break; } } if (!endCODOP) { linea = procesos.escribirError("", "No se encontró el fin del archivo", 0); archivo.escribirErr(linea); } // Escribe el archivo inst en el cuadro de texto jtxtInst.setText(""); try { textoInst = archivo.leerArchivo(archivo.nombreArchivo + ".inst"); jtxtInst.setText(textoInst); } catch (IOException a) { } // Escribe el archivo err en el cuadro de texto jtxtErr.setText(""); try { textoErr = archivo.leerArchivo(archivo.nombreArchivo + ".err"); jtxtErr.setText(textoErr); } catch (IOException a) { } } else { JOptionPane.showMessageDialog(null, "Primero carga el archivo asm"); } } }
void manejo(String gtext) { String cadena = ""; String combo[] = null; // ETQ+INST+OPER+TYPE String CAL = "0000"; String CL = "00"; String TBS = ""; int scl = 0; String ETQ = ""; String INS = ""; String OPE = ""; String DIR = ""; String ACU = ""; String COL = ""; String COB = ""; StringTokenizer cutxt = new StringTokenizer(gtext, "\n"); while (cutxt.hasMoreTokens()) { Cadenatxt analizador = new Cadenatxt(); cadena = analizador.DeleteComment(cutxt.nextToken()); // Quitar Comentario Si es que lo trae. combo = analizador.Cortador(cadena, CAL); int cln = 0; int cl = 0; ETQ = ""; INS = ""; OPE = ""; DIR = ""; ACU = ""; COL = ""; COB = ""; Acu = Dirr; if (combo[1].compareTo("ORG") == 0) { // System.out.println("ETQ "+combo[0]+"\t\t INST "+combo[1]+"\t\tOPER "+combo[2]+"\t\tDIR // "+combo[3]+"\t\tACU "+combo[4]+"\t CL "+combo[5]+"CB "+combo[6]); System.out.println( combo[5] + "\t\t " + combo[4] + "\t\t " + combo[0] + "\t\t " + combo[1] + "\t\t " + combo[2]); while (combo[5].length() < 4) { combo[5] = "0" + combo[5]; } CL = combo[5]; ETQ = combo[0]; INS = combo[1]; OPE = combo[2]; DIR = combo[3]; ACU = combo[4]; COL = combo[5]; COB = combo[6]; } else if (combo[1].compareTo("EQU") == 0) { // System.out.println("ETQ "+combo[0]+"\t\t INST "+combo[1]+"\t\tOPER "+combo[2]+"\t\tDIR // "+combo[3]+"\t\tACU "+combo[4]+"\t CL "+combo[5]+"CB "+combo[6]); System.out.println( combo[5] + "\t\t " + combo[4] + "\t\t " + combo[0] + "\t\t " + combo[1] + "\t\t " + combo[2]); while (combo[5].length() < 4) { combo[5] = "0" + combo[5]; } TBS += combo[0] + "\t" + combo[5] + "\n"; ETQ = combo[0]; INS = combo[1]; OPE = combo[2]; DIR = combo[3]; ACU = combo[4]; COL = combo[5]; COB = combo[6]; } else if (combo[1].length() != 0) { // System.out.println("ETQ "+combo[0]+"\t\t INST "+combo[1]+"\t\tOPER "+combo[2]+"\t\tDIR // "+combo[3]+"\t\tACU "+combo[4]+"\t CL "+CL+" CB "+combo[6]); System.out.println( CL + "\t\t " + combo[4] + "\t\t " + combo[0] + "\t\t " + combo[1] + "\t\t " + combo[2]); if (combo[0].length() > 0 && combo[1].compareTo("EQU") != 0) { while (CL.length() < 4) { CL = "0" + CL; } TBS += combo[0] + "\t" + CL + "\n"; } ETQ = combo[0]; INS = combo[1]; OPE = combo[2]; DIR = combo[3]; ACU = combo[4]; COL = CL; COB = combo[6]; cl = Integer.parseInt(combo[5], 16); cln = Integer.parseInt(CL, 16); scl = cl + cln; CL = Integer.toString(scl, 16); while (CL.length() < 4) { CL = "0" + CL; } } agregarZapatos(ETQ, INS, OPE, DIR, ACU, COL, COB); } System.out.println("\n\n\tTBS \n" + TBS); Archivo lstx = new Archivo(); lstx.GuardaArchivo(TBS, fc, "Prueba.tbs"); imprimir(); }