List of usage examples for java.io ObjectInputStream close
public void close() throws IOException
From source file:org.socialhistoryservices.security.MongoTokenStore.java
private static <T> T deserialize(byte[] byteArray) { ObjectInputStream oip = null; try {//w w w . j a va 2s . c o m oip = new ObjectInputStream(new ByteArrayInputStream(byteArray)); return (T) oip.readObject(); } catch (IOException e) { throw new IllegalArgumentException(e); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(e); } finally { if (oip != null) { try { oip.close(); } catch (IOException e) { // eat it } } } }
From source file:com.hp.saas.agm.rest.client.SessionContext.java
public static SessionContext load(File sourceFile) { ObjectInputStream in = null; try {// w w w .ja v a 2s.c o m in = new ObjectInputStream(new FileInputStream(sourceFile)); return (SessionContext) in.readObject(); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (InvalidClassException e) { throw new InvalidFormatException(e); } catch (IOException e) { throw new RuntimeException(e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { logger.log(Level.SEVERE, "IOException thrown while closing stream.", e); } } } }
From source file:com.openteach.diamond.network.waverider.slave.SlaveState.java
public static SlaveState fromByteBuffer(ByteBuffer buffer) { ByteArrayInputStream bin = null; ObjectInputStream oin = null; try {//from ww w . j ava2 s . c o m bin = new ByteArrayInputStream(buffer.array(), Packet.getHeaderSize() + Command.getHeaderSize(), buffer.remaining()); oin = new ObjectInputStream(bin); return (SlaveState) oin.readObject(); } catch (IOException e) { logger.error(e); throw new RuntimeException(e); } catch (ClassNotFoundException e) { logger.error(e); throw new RuntimeException(e); } finally { if (oin != null) { try { oin.close(); } catch (IOException e) { logger.error(e); } } } }
From source file:Main.java
public static Object getAsObject(String key) { byte[] data = getAsBinary(key); if (data != null) { ByteArrayInputStream bais = null; ObjectInputStream ois = null; try {//w w w.ja v a2 s . co m bais = new ByteArrayInputStream(data); ois = new ObjectInputStream(bais); Object reObject = ois.readObject(); return reObject; } catch (Exception e) { e.printStackTrace(); return null; } finally { try { if (bais != null) bais.close(); } catch (IOException e) { e.printStackTrace(); } try { if (ois != null) ois.close(); } catch (IOException e) { e.printStackTrace(); } } } return null; }
From source file:com.newatlanta.appengine.datastore.CachingDatastoreService.java
private static Object deserialize(HttpServletRequest req) throws Exception { if (req.getContentLength() == 0) { return null; }/*from w w w . j a v a 2 s.c o m*/ byte[] bytesIn = new byte[req.getContentLength()]; req.getInputStream().readLine(bytesIn, 0, bytesIn.length); if (isDevelopment()) { // workaround for issue #2097 bytesIn = decodeBase64(bytesIn); } ObjectInputStream objectIn = new ObjectInputStream( new BufferedInputStream(new ByteArrayInputStream(bytesIn))); try { return objectIn.readObject(); } finally { objectIn.close(); } }
From source file:com.titilink.camel.rest.util.CommonUtils.java
/** * clone ? ?//w w w . jav a2 s . c om * * @param obj ? * @return ? */ public static Object clone(Object obj) { if (obj == null) { return null; } Object anotherObj = null; byte[] bytes = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; try { oos = new ObjectOutputStream(baos); oos.writeObject(obj); bytes = baos.toByteArray(); } catch (Exception ex) { LOGGER.error("CloneObjectUtil cloneexception ", ex); return null; } finally { if (oos != null) { try { oos.close(); } catch (Exception e) { LOGGER.error("CloneObjectUtil cloneexception ", e); } } } ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = null; try { ois = new ObjectInputStream(bais); anotherObj = ois.readObject(); } catch (Exception ex) { LOGGER.error("CloneObjectUtil cloneexception ", ex); return null; } finally { if (ois != null) { try { ois.close(); } catch (Exception e) { LOGGER.error("CloneObjectUtil cloneexception ", e); } } } return anotherObj; }
From source file:be.vdab.util.Programma.java
private static TreeSet<Voertuig> lees(String file) {//gekozen voor treeSet , zo duidelijk dat er een TreeSet uitkomt (die serialiseerbaar is) TreeSet<Voertuig> voertuigen = null; ObjectInputStream ois = null; try {/*from w w w .j a v a 2 s . c om*/ FileInputStream fis = new FileInputStream(file); ois = new ObjectInputStream(fis); voertuigen = (TreeSet<Voertuig>) ois.readObject();//je moet exact weten wat er is ingegaan, anders kan je object niet casten naar juiste klasse!? } catch (FileNotFoundException fnfe) { System.out.println(fnfe.getMessage()); } catch (IOException ioe) { System.out.println(ioe.getMessage()); } catch (ClassNotFoundException cnfe) { System.out.println(cnfe.getMessage()); } finally { try { ois.close(); } catch (IOException ioe) { System.err.println(" ioe.getMessage()"); } } return voertuigen; }
From source file:com.openteach.diamond.network.waverider.master.MasterState.java
public static MasterState fromByteBuffer(ByteBuffer buffer) { ByteArrayInputStream bin = null; ObjectInputStream oin = null; try {/*from ww w . java 2s .c o m*/ bin = new ByteArrayInputStream(buffer.array(), Packet.getHeaderSize() + Command.getHeaderSize(), buffer.remaining()); oin = new ObjectInputStream(bin); return (MasterState) oin.readObject(); } catch (IOException e) { logger.error(e); throw new RuntimeException(e); } catch (ClassNotFoundException e) { logger.error(e); throw new RuntimeException(e); } finally { try { if (oin != null) { oin.close(); } if (bin != null) { bin.close(); } } catch (IOException e) { logger.error(e); } } }
From source file:Main.java
public static final Object RestoreObject(final String path) { FileInputStream fileInputStream = null; ObjectInputStream objectInputStream = null; Object object = null;//from ww w . ja v a2s . co m File file = new File(path); if (!file.exists()) { return null; } try { fileInputStream = new FileInputStream(file); objectInputStream = new ObjectInputStream(fileInputStream); object = objectInputStream.readObject(); return object; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } finally { try { if (objectInputStream != null) { objectInputStream.close(); } if (fileInputStream != null) { fileInputStream.close(); } } catch (IOException e) { e.printStackTrace(); } } return object; }
From source file:de.tudarmstadt.ukp.dkpro.tc.mallet.util.MalletUtils.java
public static TransducerEvaluator runTestCRF(File testFile, File modelFile) throws FileNotFoundException, IOException, ClassNotFoundException { Reader testFileReader = null; InstanceList testData = null;/* ww w .jav a 2 s . c om*/ //testFileReader = new FileReader(testFile); testFileReader = new InputStreamReader(new GZIPInputStream(new FileInputStream(testFile)), "UTF-8"); Pipe p = null; CRF crf = null; TransducerEvaluator eval = null; ObjectInputStream s = new ObjectInputStream(new FileInputStream(modelFile)); crf = (CRF) s.readObject(); s.close(); p = crf.getInputPipe(); p.setTargetProcessing(true); testData = new InstanceList(p); testData.addThruPipe(new LineGroupIterator(testFileReader, Pattern.compile("^\\s*$"), true)); // logger.info ("Number of predicates: "+p.getDataAlphabet().size()); eval = new PerClassEvaluator(new InstanceList[] { testData }, new String[] { "Testing" }); if (p.isTargetProcessing()) { Alphabet targets = p.getTargetAlphabet(); StringBuffer buf = new StringBuffer("Labels:"); for (int i = 0; i < targets.size(); i++) { buf.append(" ").append(targets.lookupObject(i).toString()); // logger.info(buf.toString()); } } test(new NoopTransducerTrainer(crf), eval, testData); List<String> labels = ((PerClassEvaluator) eval).getLabelNames(); List<Double> precisionValues = ((PerClassEvaluator) eval).getPrecisionValues(); List<Double> recallValues = ((PerClassEvaluator) eval).getRecallValues(); List<Double> f1Values = ((PerClassEvaluator) eval).getF1Values(); printEvaluationMeasures(labels, precisionValues, recallValues, f1Values); return eval; }