List of usage examples for java.io ObjectInputStream close
public void close() throws IOException
From source file:com.marintek.isis.wicket.popupbox.applib.PopupWicketBoxSemanticsProvider.java
static Object fromString(String s) { final byte[] data = Base64.decodeBase64(s); ObjectInputStream ois = null; try {/* w w w . j a v a 2 s . c o m*/ ois = new ObjectInputStream(new ByteArrayInputStream(data)); return ois.readObject(); } catch (IOException e) { throw new Base64Serializer.Exception(e); } catch (ClassNotFoundException e) { throw new Base64Serializer.Exception(e); } finally { try { if (ois != null) { ois.close(); } } catch (IOException e) { throw new Base64Serializer.Exception(e); } } }
From source file:brainleg.app.util.AppUtil.java
/** * <p>Deserializes an <code>Object</code> from the specified stream.</p> * <p/>/* w w w . ja va2 s . c o m*/ * <p>The stream will be closed once the object is written. This * avoids the need for a finally clause, and maybe also exception * handling, in the application code.</p> * <p/> * <p>The stream passed in is not buffered internally within this method. * This is the responsibility of your application if desired.</p> * * @param inputStream the serialized object input stream, must not be null * @return the deserialized object * @throws IllegalArgumentException if <code>inputStream</code> is <code>null</code> * @throws SerializationException (runtime) if the serialization fails */ public static Object deserialize(InputStream inputStream) { if (inputStream == null) { throw new IllegalArgumentException("The InputStream must not be null"); } ObjectInputStream in = null; try { // stream closed in the finally in = new ObjectInputStream(inputStream); return in.readObject(); } catch (ClassNotFoundException ex) { throw new SerializationException(ex); } catch (IOException ex) { throw new SerializationException(ex); } finally { try { if (in != null) { in.close(); } } catch (IOException ex) { // ignore close exception } } }
From source file:com.microsoft.azure.management.datalake.store.uploader.UploadMetadata.java
/** * Attempts to load an UploadMetadata object from the given file. * * @param filePath The full path to the file where to load the metadata from * @return A deserialized {@link UploadMetadata} object from the file specified. * @throws FileNotFoundException Thrown if the filePath is inaccessible or does not exist * @throws InvalidMetadataException Thrown if the metadata is not in the expected format. *//*from w w w. j av a 2 s .c o m*/ public static UploadMetadata loadFrom(String filePath) throws FileNotFoundException, InvalidMetadataException { if (!new File(filePath).exists()) { throw new FileNotFoundException("Could not find metadata file: " + filePath); } UploadMetadata result = null; try { FileInputStream fileIn = new FileInputStream(filePath); ObjectInputStream in = new ObjectInputStream(fileIn); result = (UploadMetadata) in.readObject(); in.close(); fileIn.close(); result.metadataFilePath = filePath; return result; } catch (Exception ex) { throw new InvalidMetadataException("Unable to parse metadata file", ex); } }
From source file:edu.harvard.i2b2.Icd9ToSnomedCT.BinResourceFromIcd9ToSnomedCTMap.java
public static HashMap<String, String> deSerializeIcd9CodeToNameMap() throws IOException { logger.debug("loading map.."); HashMap<String, String> map = null; ObjectInputStream ois = null; InputStream fis = null;//from w w w. j ava 2 s. c o m try { fis = BinResourceFromIcd9ToSnomedCTMap.class.getResourceAsStream(binFileName); if (fis == null) logger.error("mapping file not found:" + binFileName); ois = new ObjectInputStream(fis); map = (HashMap<String, String>) ois.readObject(); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { ois.close(); fis.close(); } logger.debug("..loaded"); return map; }
From source file:net.myrrix.common.io.IOUtils.java
/** * @return object of type T that was serialized into the given file *//*from www . j ava2 s. c o m*/ public static <T extends Serializable> T readObjectFromFile(File f, Class<T> clazz) throws IOException { ObjectInputStream in = new ObjectInputStream(openMaybeDecompressing(f)); try { @SuppressWarnings("unchecked") T result = (T) in.readObject(); return result; } catch (ClassNotFoundException cnfe) { throw new IllegalStateException(cnfe); } finally { in.close(); } }
From source file:com.joliciel.jochre.lexicon.TextFileLexicon.java
public static TextFileLexicon deserialize(File memoryBaseFile) { LOG.debug("deserializeMemoryBase"); boolean isZip = false; if (memoryBaseFile.getName().endsWith(".zip")) isZip = true;/*w w w .j a v a 2 s. co m*/ TextFileLexicon memoryBase = null; ZipInputStream zis = null; FileInputStream fis = null; ObjectInputStream in = null; try { fis = new FileInputStream(memoryBaseFile); if (isZip) { zis = new ZipInputStream(fis); memoryBase = TextFileLexicon.deserialize(zis); } else { in = new ObjectInputStream(fis); memoryBase = (TextFileLexicon) in.readObject(); in.close(); } } catch (IOException ioe) { throw new RuntimeException(ioe); } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } return memoryBase; }
From source file:license.regist.ReadProjectInfo.java
static PublicKey readPublicKeyFromFile() throws Exception { ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(KeyData.publicKey)); try {/*from ww w . j a va 2 s . c o m*/ BigInteger m = (BigInteger) oin.readObject(); BigInteger e = (BigInteger) oin.readObject(); RSAPublicKeySpec keySpec = new RSAPublicKeySpec(m, e); KeyFactory fact = KeyFactory.getInstance("RSA"); return fact.generatePublic(keySpec); } finally { oin.close(); } }
From source file:hudson.console.ConsoleNote.java
/** * Reads a note back from {@linkplain #encodeTo(OutputStream) its encoded form}. * * @param in/*from ww w .j ava 2 s.c o m*/ * Must point to the beginning of a preamble. * * @return null if the encoded form is malformed. */ public static ConsoleNote readFrom(DataInputStream in) throws IOException, ClassNotFoundException { try { byte[] preamble = new byte[PREAMBLE.length]; in.readFully(preamble); if (!Arrays.equals(preamble, PREAMBLE)) return null; // not a valid preamble DataInputStream decoded = new DataInputStream(new UnbufferedBase64InputStream(in)); int sz = decoded.readInt(); byte[] buf = new byte[sz]; decoded.readFully(buf); byte[] postamble = new byte[POSTAMBLE.length]; in.readFully(postamble); if (!Arrays.equals(postamble, POSTAMBLE)) return null; // not a valid postamble ObjectInputStream ois = new ObjectInputStreamEx(new GZIPInputStream(new ByteArrayInputStream(buf)), Jenkins.getInstance().pluginManager.uberClassLoader); try { return (ConsoleNote) ois.readObject(); } finally { ois.close(); } } catch (Error e) { // for example, bogus 'sz' can result in OutOfMemoryError. // package that up as IOException so that the caller won't fatally die. throw new IOException(e); } }
From source file:com.code.savemarks.utils.Utils.java
/** * Deserialize an object from a byte array. Does not throw any exceptions; * instead, exceptions are logged and null is returned. * /*from ww w. ja v a2 s .c om*/ * @param bytesIn A byte array containing a previously serialized object. * @return An object instance, or null if an exception occurred. */ public static Object deserialize(byte[] bytesIn) { ObjectInputStream objectIn = null; try { bytesIn = decodeBase64(bytesIn); objectIn = new ObjectInputStream(new BufferedInputStream(new ByteArrayInputStream(bytesIn))); return objectIn.readObject(); } catch (Exception e) { log.log(Level.SEVERE, "Error deserializing task", e); return null; // don't retry task } finally { try { if (objectIn != null) { objectIn.close(); } } catch (IOException ignore) { } } }
From source file:com.ery.ertc.estorm.util.ToolUtil.java
public static Object deserializeObject(String serStr, boolean isGzip, boolean urlEnCode) throws IOException { byte[] bts = null; if (urlEnCode) { bts = org.apache.commons.codec.binary.Base64.decodeBase64(serStr.getBytes("ISO-8859-1")); } else {/*from w ww . j a va 2 s . c om*/ bts = serStr.getBytes("ISO-8859-1"); } if (isGzip) bts = GZIPUtils.unzip(bts); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bts); ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream); try { return objectInputStream.readObject(); } catch (ClassNotFoundException e) { e.printStackTrace(); throw new IOException(e); } finally { objectInputStream.close(); byteArrayInputStream.close(); } }