List of usage examples for java.io ObjectOutputStream close
public void close() throws IOException
From source file:com.adaptris.util.datastore.SimpleDataStore.java
private void writeData(HashMap data) throws IOException { // write the object out... FileOutputStream out = new FileOutputStream(getDataFileName()); ObjectOutputStream objOut = new ObjectOutputStream(out); objOut.writeObject(data);/*from w ww. j ava 2s .c om*/ objOut.close(); out.close(); }
From source file:epn.edu.ec.bibliotecadigital.servidor.ServerRunnable.java
@Override public void run() { try {/*from w w w .j a va 2 s .c o m*/ DataInputStream dataIn = new DataInputStream(clientSocket.getInputStream()); DataOutputStream dataOut = new DataOutputStream(clientSocket.getOutputStream()); OutputStream out; String accion = dataIn.readUTF(); Libro lbr; String nombreUsuario = dataIn.readUTF(); System.out.println("nombreUsuario" + nombreUsuario); switch (accion) { case "bajar": String codArchivo = dataIn.readUTF(); dataOut = new DataOutputStream(clientSocket.getOutputStream()); lbr = new LibroJpaController(emf).findLibro(Integer.parseInt(codArchivo)); if (lbr == null) { dataOut.writeBoolean(false); break; } dataOut.writeBoolean(true); //File file = new File("C:\\Computacion Distribuida\\" + lbr.getNombre()); dataOut.writeUTF(lbr.getNombre()); out = clientSocket.getOutputStream(); try { byte[] bytes = new byte[64 * 1024]; InputStream in = new ByteArrayInputStream(lbr.getArchivo()); int count; while ((count = in.read(bytes)) > 0) { out.write(bytes, 0, count); } Usuariolibros usrLbr = new Usuariolibros(); usrLbr.setFecha(Calendar.getInstance().getTime()); usrLbr.setAccion('B'); usrLbr.setCodigolibro(lbr); usrLbr.setNombrecuenta(new Usuario(nombreUsuario)); new UsuariolibrosJpaController(emf).create(usrLbr); in.close(); } finally { IOUtils.closeQuietly(out); } break; case "subir": dataIn = new DataInputStream(clientSocket.getInputStream()); String fileName = dataIn.readUTF(); InputStream in = clientSocket.getInputStream(); try { out = new FileOutputStream("C:\\Computacion Distribuida\\" + fileName); byte[] bytes = new byte[64 * 1024]; int count; while ((count = in.read(bytes)) > 0) { out.write(bytes, 0, count); } out.close(); lbr = new Libro(); lbr.setNombre(fileName); lbr.setArchivo( IOUtils.toByteArray(new FileInputStream("C:\\Computacion Distribuida\\" + fileName))); new LibroJpaController(emf).create(lbr); Usuariolibros usrLbr = new Usuariolibros(); usrLbr.setFecha(Calendar.getInstance().getTime()); usrLbr.setAccion('S'); usrLbr.setCodigolibro(lbr); usrLbr.setNombrecuenta(new Usuario(nombreUsuario)); new UsuariolibrosJpaController(emf).create(usrLbr); actualizarLibrosEnServidores(fileName); } finally { IOUtils.closeQuietly(in); } break; case "obtenerLista": ObjectOutputStream outToServer = new ObjectOutputStream(clientSocket.getOutputStream()); outToServer.writeObject(new LibroJpaController(emf).findLibroEntities()); outToServer.close(); break; case "verificarEstado": dataOut.writeUTF(String.valueOf(server.isDisponible())); break; case "actualizar": dataIn = new DataInputStream(clientSocket.getInputStream()); String fileNameFromServer = dataIn.readUTF(); in = clientSocket.getInputStream(); try { out = new FileOutputStream("C:\\Computacion Distribuida\\" + fileNameFromServer); byte[] bytes = new byte[64 * 1024]; int count; while ((count = in.read(bytes)) > 0) { out.write(bytes, 0, count); } out.close(); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(in); } } dataIn.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:de.jwic.base.SessionManager.java
/** * Write the session to a temporary directory. * @param container//from w ww . ja v a 2 s . co m */ public void serialize(SessionContainer container) { log.debug("Serializing container " + container); String filename = container.getClientId() + "_" + container.getId() + ".ser"; try { SessionContext sc = container.getSessionContext(); sc.fireEvent(new SessionEvent(null), SessionContext.BEFORE_SERIALIZATION); FileOutputStream fos = new FileOutputStream(new File(serDir, filename)); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(sc); oos.close(); container.setState(SessionContainer.STATE_STORED); container.setSessionContext(null); // release SessionContext } catch (Exception e) { log.error("Error storing session", e); throw new JWicException("Serialization failed. Can not serialize session.", e); } }
From source file:net.sf.nmedit.jpatch.ModuleDescriptions.java
public void writeCache(File cache) throws FileNotFoundException, IOException { ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(cache))); try {/*from w ww .j a v a 2 s .com*/ writeCache(out); } finally { out.flush(); out.close(); } }
From source file:com.ibuildapp.romanblack.CouponPlugin.CouponAdapter.java
/** * Set disk cache path to store downloaded rss images * @param cachePath - disk cache path// www . ja v a 2s . c o m */ public void setCachePath(String cachePath) { this.cachePath = cachePath; try { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(cachePath + "/cache.data")); oos.writeObject(items); oos.flush(); oos.close(); } catch (Exception e) { } }
From source file:com.ibuildapp.romanblack.CouponPlugin.CouponAdapter.java
private void downloadRegistration(int position, String value) { this.items.get(position).setImagePath(value); try {//from w ww. j av a 2 s . c om ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(cachePath + "/cache.data")); oos.writeObject(items); oos.flush(); oos.close(); Log.d("IMAGES PLUGIN CACHE DATA", "SUCCESS"); } catch (Exception e) { Log.w("IMAGES PLUGIN CACHE DATA", e); } }
From source file:com.aurel.track.exchange.excel.ExcelFieldMatchAction.java
/** * Save the field mappings for the next use * @return/*w w w.ja v a 2 s . c o m*/ */ public String save() { workbook = ExcelFieldMatchBL.loadWorkbook(excelMappingsDirectory, fileName); SortedMap<Integer, String> columnIndexToColumNameMap = ExcelFieldMatchBL.getFirstRowHeaders(workbook, selectedSheet); Map<String, Integer> columNameToFieldIDMap = ExcelFieldMatchBL .getColumnNameToFieldIDMap(columnIndexToFieldIDMap, columnIndexToColumNameMap); Set<Integer> lastSavedIdentifierFieldIDIsSet = new HashSet<Integer>(); //add the explicitly selected field identifiers if (columnIndexIsIdentifierMap != null) { //at least a field was set as unique identifier Iterator<Integer> iterator = columnIndexIsIdentifierMap.keySet().iterator(); while (iterator.hasNext()) { Integer columnIndex = iterator.next(); Integer fieldID = columnIndexToFieldIDMap.get(columnIndex); Boolean isIdentifier = columnIndexIsIdentifierMap.get(columnIndex); if ((isIdentifier != null && isIdentifier.booleanValue())) { lastSavedIdentifierFieldIDIsSet.add(fieldID); } } } //add the implicitly selected field identifiers //the mandatory identifiers are disabled (to forbid unselecting them), //but it means that they will not be submitted by columnIndexIsIdentifierMap //so we should add them manually if a mandatoryIdentifierFields is mapped Set<Integer> mandatoryIdentifierFields = ExcelFieldMatchBL.getMandatoryIdentifierFields(); Iterator<Integer> iterator = mandatoryIdentifierFields.iterator(); Collection<Integer> submittedFieldIDs = columnIndexToFieldIDMap.values(); while (iterator.hasNext()) { Integer mandatoryIdentifierField = iterator.next(); if (submittedFieldIDs.contains(mandatoryIdentifierField)) { lastSavedIdentifierFieldIDIsSet.add(mandatoryIdentifierField); } } try { FileOutputStream fos = new FileOutputStream(new File(excelMappingsDirectory, mappingFileName)); ObjectOutputStream out = new ObjectOutputStream(fos); out.writeObject(columNameToFieldIDMap); out.writeObject(lastSavedIdentifierFieldIDIsSet); out.close(); } catch (FileNotFoundException e) { LOGGER.warn("Creating the output stream for mapping failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } catch (IOException e) { LOGGER.warn("Saving the mapping failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } return NEXT; }
From source file:hudson.console.ConsoleNote.java
private ByteArrayOutputStream encodeToBytes() throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(buf)); try {/*from w w w .j ava2s . c om*/ oos.writeObject(this); } finally { oos.close(); } ByteArrayOutputStream buf2 = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(new Base64OutputStream(buf2, true, -1, null)); try { buf2.write(PREAMBLE); dos.writeInt(buf.size()); buf.writeTo(dos); } finally { dos.close(); } buf2.write(POSTAMBLE); return buf2; }
From source file:FileGameAccess.java
@SuppressWarnings("resource") private boolean saveSerialize(Serializable obj, String fName) { FileOutputStream fout;//from w w w .j a va 2 s. c o m try { fout = new FileOutputStream(fName, false); } catch (FileNotFoundException ex) { Logger.getLogger(FileGameAccess.class.getName()).log(Level.SEVERE, null, ex); return false; } ObjectOutputStream oos; try { oos = new ObjectOutputStream(fout); } catch (IOException ex) { Logger.getLogger(FileGameAccess.class.getName()).log(Level.SEVERE, null, ex); return false; } try { oos.writeObject(obj); oos.close(); fout.close(); } catch (IOException ex) { Logger.getLogger(FileGameAccess.class.getName()).log(Level.SEVERE, null, ex); return false; } return true; }
From source file:edu.harvard.i2b2.Icd9.BinResourceFromIcd9Data.java
public void serializeIcd9CodeToNameMap() throws IOException { FileOutputStream fos = null;//from w ww . ja v a 2 s.c o m ObjectOutputStream oos = null; try { fos = new FileOutputStream("Icd9CodeToNameMap.bin"); oos = new ObjectOutputStream(fos); oos.writeObject(Icd9CodeToNameMap); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { fos.close(); oos.close(); } }