List of usage examples for java.io ObjectInputStream close
public void close() throws IOException
From source file:com.ibm.sbt.test.lib.MockSerializer.java
private Object deserialize(String o) throws IOException { ObjectInputStream is = new ObjectInputStream(new ByteArrayInputStream(o.getBytes())); try {/*from w w w. j a v a2s . co m*/ return is.readObject(); } catch (ClassNotFoundException e) { throw new IOException(e); } finally { is.close(); } }
From source file:epn.edu.ec.bibliotecadigital.cliente.Client.java
@Override public void run() { try {/* w ww. j a va 2s. co m*/ clientSocketBalancer = new Socket(InetAddress.getByName(serverIP), portBalancer); DataInputStream dataInBalancer = new DataInputStream(clientSocketBalancer.getInputStream()); DataOutputStream dataOut = new DataOutputStream(clientSocketBalancer.getOutputStream()); dataOut.writeUTF((String) params[0]);//nombre de usuario String ipServer = dataInBalancer.readUTF(); int portServer = dataInBalancer.readInt(); clientSocketBalancer.close(); Socket clientSocket = new Socket(ipServer, portServer); dataOut = new DataOutputStream(clientSocket.getOutputStream()); dataOut.writeUTF(accion); dataOut.writeUTF((String) params[0]);//nombre de usuario InputStream in; DataInputStream dataIn; switch (accion) { case "bajar": dataOut = new DataOutputStream(clientSocket.getOutputStream()); dataOut.writeUTF((String) params[1]); dataIn = new DataInputStream(clientSocket.getInputStream()); boolean encontrado = dataIn.readBoolean(); if (!encontrado) { System.out.println("Libro con el cdigo: " + params[1] + " no encontrado"); break; } String fileName = dataIn.readUTF(); System.out.println( "Descargando libro " + fileName + " con cdigo " + params[1] + " en la carpeta Donwloads"); String home = System.getProperty("user.home"); in = clientSocket.getInputStream(); try { FileOutputStream out = new FileOutputStream(new File(home + "\\Downloads\\" + fileName)); 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); } break; case "subir": dataOut = new DataOutputStream(clientSocket.getOutputStream()); dataOut.writeUTF(((File) params[1]).getName()); OutputStream out = clientSocket.getOutputStream(); try { byte[] bytes = new byte[64 * 1024]; in = new FileInputStream((File) params[1]); int count; while ((count = in.read(bytes)) > 0) { out.write(bytes, 0, count); } in.close(); } finally { IOUtils.closeQuietly(out); } break; case "obtenerLista": ObjectInputStream inFromClient = new ObjectInputStream(clientSocket.getInputStream()); System.out.println("Libros disponibles: \n"); List<Libro> libros = (List<Libro>) inFromClient.readObject(); System.out.println("\tCdigo\tNommbre\n"); for (Libro lbr : libros) { System.out.println("\t" + lbr.getCodigolibro() + "\t" + lbr.getNombre()); } inFromClient.close(); break; case "verificar": break; } dataOut.close(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException ex) { Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.google.code.facebook.graph.sna.applet.FacebookGraphApplet.java
/** * /*from w w w. jav a 2 s .com*/ */ @SuppressWarnings("unchecked") private void fetchUserGraph() { try { String accessToken = getParameter("accessToken"); URL url = new URL("http://facebookgraph.appspot.com/fetchGraph?accessToken=" + encodeUrl(accessToken)); HttpURLConnection request = (HttpURLConnection) url.openConnection(); request.connect(); if (request.getResponseCode() == HttpURLConnection.HTTP_OK) { GraphAdapter<Graph<Entity<FieldEnum, ConnectionEnum>, EdgeAdapter<ConnectionEnum>>, Entity<FieldEnum, ConnectionEnum>, ConnectionEnum> adapter = new JungGraphAdapter<Entity<FieldEnum, ConnectionEnum>, ConnectionEnum>(); ObjectInputStream is = new ObjectInputStream(new GZIPInputStream(request.getInputStream())); graph = adapter.adaptFrom((GraphNode<? extends FieldEnum, ConnectionEnum>) is.readObject()); is.close(); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.izforge.izpack.installer.multiunpacker.MultiVolumeUnpackerTest.java
/** * Helper to read the pack meta-data.//from w w w. j av a 2s. c o m * * @param resources the resources * @return the pack meta-data * @throws IOException for any I/O error * @throws ClassNotFoundException if the class of a serialized object cannot be found */ private List<Pack> getPacks(Resources resources) throws IOException, ClassNotFoundException { // We read the packs data InputStream in = resources.getInputStream("packs.info"); ObjectInputStream objIn = new ObjectInputStream(in); List<PackInfo> packsInfo = (List<PackInfo>) objIn.readObject(); objIn.close(); List<Pack> packs = new ArrayList<Pack>(); for (PackInfo packInfo : packsInfo) { Pack pack = packInfo.getPack(); packs.add(pack); } return packs; }
From source file:com.easytrack.component.system.LicenseCheck.java
private LicenseCheck() throws Exception { try {//from ww w .ja v a2 s . co m try { // String file = Config.getHomeDir(); // if (file == null) { // if ("Windows".startsWith(System.getProperty("os.name"))) // file = "D:/EasyTrack"; // else { // file = "/home/easytrack"; // } // } String file = "D:/EasyTrack"; // File f = new File(file + "/config/license.lic"); File f = new File(file + "/config2/license.lic"); if (f.exists()) { FileInputStream o = new FileInputStream(f); ObjectInputStream in = new ObjectInputStream(o); this.license = ((License) in.readObject()); System.out.println(this.license.toString()); System.out.println("-------------------"); in.close(); o.close(); } } catch (Exception e) { e.printStackTrace(); this.license = new License(); } checkLicense(this.license); String s = Config.getConfig("LICENSE", "ALERT-THRESHOLD"); this.alertThreshold = (Integer.parseInt(s) / 100.0D); if (this.alertThreshold > 1.0D) { this.alertThreshold = 1.0D; } this.adminEmail = Config.getConfig("LICENSE", "ADMIN-EMAIL"); } catch (CommonException e) { throw e; } catch (Exception e) { e.printStackTrace(); throw new CommonException("InvalidLicenseKey"); } }
From source file:edu.stanford.muse.datacache.BlobStore.java
private synchronized void unpack() throws IOException { String f = this.dir + File.separatorChar + META_DATA_FILENAME; try {//from w w w . ja va 2s. c om ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f)); unpack_from_stream(ois); ois.close(); } catch (ClassNotFoundException cnfe) { log.warn("Unable to read existing metadata file for blobstore: " + f + "\nDeleting it..."); boolean b = new File(f).delete(); log.warn("delete succeeded:" + b); } }
From source file:org.eclipse.thym.core.internal.util.BundleHttpCacheStorage.java
@Override public HttpCacheEntry getEntry(String key) throws IOException { File f = getCacheFile(key);/*from ww w.j a v a 2 s.co m*/ if (f.exists()) { ByteArrayInputStream bais = null; ObjectInputStream ois = null; HttpCacheEntry entry = null; try { byte[] bytes = FileUtils.readFileToByteArray(f); bais = new ByteArrayInputStream(bytes); ois = new ObjectInputStream(bais); entry = (HttpCacheEntry) ois.readObject(); } catch (ClassNotFoundException e) { HybridCore.log(IStatus.ERROR, "Missing bundle", e); } finally { if (ois != null) ois.close(); if (bais != null) bais.close(); } return entry; } return null; }
From source file:com.tecapro.inventory.common.util.CommonUtil.java
/** * decodeBase64 serializeData into InfoValue object * @param serializeData// w w w . j a va2 s . co m * @param value * @return * @throws Exception */ public Object deserialize(byte[] serializeData) throws Exception { byte[] decodebytes = Base64.decodeBase64(serializeData); ObjectInputStream istream = null; ByteArrayInputStream byteStream = null; Object result = null; try { byteStream = new ByteArrayInputStream(decodebytes); istream = new ObjectInputStream(byteStream); result = istream.readObject(); } finally { if (byteStream != null) { byteStream.close(); } if (istream != null) { istream.close(); } } return result; }
From source file:MSUmpire.LCMSPeakStructure.LCMSPeakBase.java
private boolean JavaSerializationPeakClusterRead() { if (!new File(FilenameUtils.getFullPath(ParentmzXMLName) + FilenameUtils.getBaseName(ParentmzXMLName) + "_Peak/" + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.ser").exists()) { return false; }//from w ww . j a v a 2 s. c o m try { Logger.getRootLogger().info("Reading PeakCluster serialization from file:" + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.ser..."); FileInputStream fileIn = new FileInputStream( FilenameUtils.getFullPath(ParentmzXMLName) + FilenameUtils.getBaseName(ParentmzXMLName) + "_Peak/" + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.ser"); ObjectInputStream in = new ObjectInputStream(fileIn); PeakClusters = (ArrayList<PeakCluster>) in.readObject(); in.close(); fileIn.close(); } catch (Exception ex) { Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex)); return false; } return true; }
From source file:deepschema.ExtractingTool.java
/** * Caches classes and subclasses to file. * /*from ww w . ja v a 2 s . c om*/ * @param operation : "read" or "write" */ @SuppressWarnings("unchecked") void cache(String action) { final String cacheFile = ".cache"; try { switch (action) { case "read": { ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(cacheFile)); classes = (Map<Integer, WikidataClassProperties>) ((ObjectInputStream) objectInputStream) .readObject(); instances = (Map<Integer, WikidataInstanceProperties>) ((ObjectInputStream) objectInputStream) .readObject(); objectInputStream.close(); } case "write": { ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(cacheFile)); objectOutputStream.writeObject(classes); objectOutputStream.writeObject(instances); objectOutputStream.flush(); objectOutputStream.close(); } } } catch (ClassNotFoundException | IOException e) { System.err.println("Problem while reading/writing from/to cache."); e.printStackTrace(); } }