List of usage examples for java.io ObjectInputStream ObjectInputStream
public ObjectInputStream(InputStream in) throws IOException
From source file:SaveYourDrawingToFile.java
public void actionPerformed(ActionEvent e) { if (e.getSource() == clearBtn) { displayList = new Vector(); repaint();/*from www .j a v a 2 s . c om*/ } else if (e.getSource() == saveBtn) { try { FileOutputStream fos = new FileOutputStream(pathname); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(displayList); oos.flush(); oos.close(); fos.close(); } catch (Exception ex) { System.out.println("Trouble writing display list vector"); } } else if (e.getSource() == restoreBtn) { try { FileInputStream fis = new FileInputStream(pathname); ObjectInputStream ois = new ObjectInputStream(fis); displayList = (Vector) (ois.readObject()); ois.close(); fis.close(); repaint(); } catch (Exception ex) { System.out.println("Trouble reading display list vector"); } } else if (e.getSource() == quitBtn) { setVisible(false); dispose(); System.exit(0); } }
From source file:edu.jhu.hlt.parma.inference.transducers.StringEditModelTrainer.java
private StringEditModel readModel(String filename) { System.err.println("Reading model from: " + filename); try {//from www . j a v a 2s . com ObjectInputStream objIn = new ObjectInputStream(new FileInputStream(filename)); return (StringEditModel) objIn.readObject(); } catch (IOException e) { System.out.println(e.getMessage()); e.printStackTrace(); System.exit(1); } catch (ClassNotFoundException c) { System.out.println(c.getMessage()); c.printStackTrace(); System.exit(1); } return null; }
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 v a 2s .c o m*/ 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(); } }
From source file:com.jpeterson.littles3.bo.AuthenticatedUsersGroupTest.java
/** * Test that an instance is serializable. *///from www .j ava 2s. c om public void test_serialization() { AuthenticatedUsersGroup group, reconstitutedGroup; ByteArrayInputStream bais; ByteArrayOutputStream baos; ObjectInputStream ois; ObjectOutputStream oos; group = AuthenticatedUsersGroup.getInstance(); try { baos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(baos); oos.writeObject(group); bais = new ByteArrayInputStream(baos.toByteArray()); ois = new ObjectInputStream(bais); reconstitutedGroup = (AuthenticatedUsersGroup) ois.readObject(); assertEquals("Unexpected value", group, reconstitutedGroup); } catch (IOException e) { e.printStackTrace(); fail("Unexpected exception"); } catch (ClassNotFoundException e) { e.printStackTrace(); fail("Unexpected exception"); } }
From source file:cascading.util.Util.java
public static Object deserializeBase64(String string, boolean decompress) throws IOException { if (string == null || string.length() == 0) return null; ObjectInputStream in = null;//from w w w . ja v a 2 s. co m try { ByteArrayInputStream bytes = new ByteArrayInputStream(Base64.decodeBase64(string.getBytes())); in = new ObjectInputStream(decompress ? new GZIPInputStream(bytes) : bytes) { @Override protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { try { return Class.forName(desc.getName(), false, Thread.currentThread().getContextClassLoader()); } catch (ClassNotFoundException exception) { return super.resolveClass(desc); } } }; return in.readObject(); } catch (ClassNotFoundException exception) { throw new FlowException("unable to deserialize data", exception); } finally { if (in != null) in.close(); } }
From source file:io.lqd.sdk.model.LQLiquidPackage.java
public static LQLiquidPackage loadFromDisk(Context context) { LQLog.data("Loading from local storage"); try {/*from w w w . j a v a 2 s. co m*/ FileInputStream fileInputStream = context.openFileInput(LIQUID_PACKAGE_FILENAME + ".vars"); ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream); Object result = objectInputStream.readObject(); objectInputStream.close(); return (LQLiquidPackage) result; } catch (IOException e) { LQLog.infoVerbose("Could not load liquid package from file"); } catch (ClassNotFoundException e) { LQLog.infoVerbose("Could not load liquid package from file"); } return new LQLiquidPackage(); }
From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.feature.lda.LDATopicsFeature.java
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { if (!super.initialize(aSpecifier, aAdditionalParams)) { return false; }//from www. j av a 2 s.com try { URL source = resolveLocation(ldaModelFile); // load(source.openStream()); // FileInputStream fis = new FileInputStream(ldaModelFile); InputStream stream = source.openStream(); ObjectInputStream ois = new ObjectInputStream(stream); this.model = (ParallelTopicModel) ois.readObject(); IOUtils.closeQuietly(stream); this.pipes = createPipes(); this.pipes.setDataAlphabet(model.getAlphabet()); for (Pipe pipe : this.pipes.pipes()) { pipe.setDataAlphabet(this.model.getAlphabet()); } // extract top words for feature naming topWords = this.model.getTopWords(10); } catch (IOException | ClassNotFoundException ex) { throw new ResourceInitializationException(ex); } return true; }
From source file:com.weibo.api.motan.protocol.restful.support.RestfulUtil.java
public static Exception getCause(BuiltResponse resp) { if (resp == null || resp.getStatus() != Status.EXPECTATION_FAILED.getStatusCode()) return null; String exceptionClass = resp.getHeaderString(EXCEPTION_HEADER); if (!StringUtils.isBlank(exceptionClass)) { String body = resp.readEntity(String.class); resp.close();//w w w . ja v a2s. co m try { ByteArrayInputStream bais = new ByteArrayInputStream( Base64.decode(body.getBytes(MotanConstants.DEFAULT_CHARACTER))); ObjectInputStream ois = new ObjectInputStream(bais); return (Exception) ois.readObject(); } catch (Exception e) { LoggerUtil.error("deserialize " + exceptionClass + " error", e); } } return null; }
From source file:net.nicholaswilliams.java.licensing.TestObjectSerializer.java
@Test public void testWriteObject2() throws Exception { MockTestObject1 object = new MockTestObject1(); object.coolTest = true;//w w w .j a va 2 s .c o m Arrays.fill(object.myArray, (byte) 12); byte[] data = this.serializer.writeObject(object); assertNotNull("The array should not be null.", data); assertTrue("The array shoudl not be empty.", data.length > 0); ByteArrayInputStream bytes = new ByteArrayInputStream(data); ObjectInputStream stream = new ObjectInputStream(bytes); Object input = stream.readObject(); assertNotNull("The object should not be null.", input); assertEquals("The object is not the right kind of object.", MockTestObject1.class, input.getClass()); MockTestObject1 actual = (MockTestObject1) input; assertFalse("The objects should not be the same object.", actual == object); assertEquals("The object is not correct.", object, actual); }
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 ww w . j a va 2 s . com*/ 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; }