List of usage examples for java.io ObjectInputStream close
public void close() throws IOException
From source file:MSUmpire.BaseDataStructure.InstrumentParameter.java
public static InstrumentParameter ReadParametersSerialization(String filepath) { if (!new File(FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + "_params.ser") .exists()) {/*from w w w . j a va 2 s.c om*/ return null; } try { Logger.getRootLogger().info("Reading parameters from file:" + FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + "_params.ser..."); FileInputStream fileIn = new FileInputStream( FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + "_params.ser"); ObjectInputStream in = new ObjectInputStream(fileIn); InstrumentParameter params = (InstrumentParameter) in.readObject(); in.close(); fileIn.close(); return params; } catch (Exception ex) { Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex)); return null; } }
From source file:net.menthor.editor.v2.util.Util.java
/** Read the object from Base64 string. */ public static Object fromBase64String(String s) throws IOException, ClassNotFoundException { byte[] data = Base64.getDecoder().decode(s); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data)); Object o = ois.readObject();/*from ww w .j av a 2 s. com*/ ois.close(); return o; }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> T readObjectFromFile(File file) { ObjectInputStream ois = null; T object = null;// w w w .j a va 2s . co m try { FileInputStream fis = new FileInputStream(file); ois = new ObjectInputStream(fis); object = (T) ois.readObject(); } catch (ClassNotFoundException | IOException e) { e.printStackTrace(); } finally { if (ois != null) { try { ois.close(); } catch (IOException e) { e.printStackTrace(); } } } return object; }
From source file:net.sf.taverna.t2.activities.wsdlsir.T2WSDLSOAPInvoker.java
/** * Read the object from Base64 string. /*ww w .j a va 2 s.c o m*/ * @param s * @return * @throws IOException * @throws ClassNotFoundException */ private static Object deserializefromString(String s) throws IOException, ClassNotFoundException { byte[] data = Base64.decode(s); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data)); Object o = ois.readObject(); ois.close(); return o; }
From source file:de.alpharogroup.io.SerializedObjectExtensions.java
/** * Reads the object from the given file. * * @param file/*from ww w.jav a2 s . com*/ * In that file is the object saved. * @return The object in the file or null. * @throws IOException * Signals that an I/O exception has occurred. * @throws ClassNotFoundException * is thrown when a class is not found in the classloader or no definition for the * class with the specified name could be found. */ public static Object readSerializedObjectFromFile(final File file) throws IOException, ClassNotFoundException { Object object = null; FileInputStream fis = null; ObjectInputStream in = null; try { fis = new FileInputStream(file); in = new ObjectInputStream(fis); object = in.readObject(); in.close(); } finally { StreamExtensions.closeInputStream(in); StreamExtensions.closeInputStream(fis); } return object; }
From source file:de.alpharogroup.io.SerializedObjectUtils.java
/** * Reads the object from the given file. * * @param file//from www . java2 s .c om * In that file is the object saved. * @return The object in the file or null. * @throws IOException * Signals that an I/O exception has occurred. * @throws ClassNotFoundException * is thrown when a class is not found in the classloader or no definition for the * class with the specified name could be found. */ public static Object readSerializedObjectFromFile(final File file) throws IOException, ClassNotFoundException { Object object = null; FileInputStream fis = null; ObjectInputStream in = null; try { fis = new FileInputStream(file); in = new ObjectInputStream(fis); object = in.readObject(); in.close(); } finally { StreamUtils.closeInputStream(in); StreamUtils.closeInputStream(fis); } return object; }
From source file:Test.java
private static void serverStart() { try {/*from w w w. j a va 2 s . c o m*/ InetSocketAddress hostAddress = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 2583); AsynchronousServerSocketChannel serverSocketChannel = AsynchronousServerSocketChannel.open() .bind(hostAddress); Future<AsynchronousSocketChannel> serverFuture = serverSocketChannel.accept(); final AsynchronousSocketChannel clientSocket = serverFuture.get(); if ((clientSocket != null) && (clientSocket.isOpen())) { InputStream connectionInputStream = Channels.newInputStream(clientSocket); ObjectInputStream ois = null; ois = new ObjectInputStream(connectionInputStream); while (true) { Object object = ois.readObject(); if (object.equals("EOF")) { clientSocket.close(); break; } System.out.println("Received :" + object); } ois.close(); connectionInputStream.close(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ecyrd.jspwiki.util.Serializer.java
/** * Deserializes a Base64-encoded String into a HashMap. Both the keys and values * must implement {@link java.io.Serializable}. * @param rawString the String contents containing the map to be deserialized * @return the attributes, parsed into a Map * @throws IOException if the contents cannot be parsed for any reason *//*from www.j a v a 2 s. c o m*/ @SuppressWarnings("unchecked") public static Map<String, ? extends Serializable> deserializeFromBase64(String rawString) throws IOException { // Decode from Base64-encoded String to byte array byte[] decodedBytes = Base64.decodeBase64(rawString.getBytes("UTF-8")); // Deserialize from the input stream to the Map InputStream bytesIn = new ByteArrayInputStream(decodedBytes); ObjectInputStream in = new ObjectInputStream(bytesIn); HashMap<String, Serializable> attributes; try { attributes = (HashMap<String, Serializable>) in.readObject(); } catch (ClassNotFoundException e) { throw new IOException("Could not deserialiaze user profile attributes. Reason: " + e.getMessage()); } finally { in.close(); } return attributes; }
From source file:com.couchbase.client.java.transcoder.TranscoderUtils.java
/** * Takes the input content and deserializes it. * * @param content the content to deserialize. * @return the serializable object.//w w w. ja va 2 s . c o m * @throws Exception if something goes wrong during deserialization. */ public static Serializable deserialize(final ByteBuf content) throws Exception { byte[] serialized = new byte[content.readableBytes()]; content.getBytes(0, serialized); ByteArrayInputStream bis = new ByteArrayInputStream(serialized); ObjectInputStream is = new ObjectInputStream(bis); Serializable deserialized = (Serializable) is.readObject(); is.close(); bis.close(); return deserialized; }
From source file:edu.harvard.i2b2.loinc.BinResourceFromLoincData.java
public static HashMap<String, String> deSerializeLoincCodeToNameMap() throws IOException { HashMap<String, String> map = null; ObjectInputStream ois = null; InputStream fis = null;/*from ww w .j a v a 2 s . c o m*/ try { fis = BinResourceFromLoincData.class.getResourceAsStream("/loinc/loincCodeToNameMap.bin"); ois = new ObjectInputStream(fis); map = (HashMap<String, String>) ois.readObject(); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { ois.close(); fis.close(); } return map; }