List of usage examples for java.io ObjectInputStream readObject
public final Object readObject() throws IOException, ClassNotFoundException
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;/* w ww . j a va 2s . c o m*/ //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; }
From source file:com.jk.util.JKObjectUtil.java
/** * Copy./*w w w. j a v a 2 s . c o m*/ * * @param source * the source * @return the object */ // ///////////////////////////////////////////////////////////////// public static Object copy(Object source) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(source); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); Object deepCopy = ois.readObject(); return deepCopy; } catch (Exception e) { throw new JKException(e); } }
From source file:edu.iu.daal_nn.NNDaalCollectiveMapper.java
private static NumericTable deserializeNumericTable(ByteArray byteArray) throws IOException, ClassNotFoundException { /* Create an input stream to deserialize the numeric table from the array */ byte[] buffer = byteArray.get(); ByteArrayInputStream inputByteStream = new ByteArrayInputStream(buffer); ObjectInputStream inputStream = new ObjectInputStream(inputByteStream); /* Create a numeric table object */ NumericTable restoredDataTable = (NumericTable) inputStream.readObject(); restoredDataTable.unpack(daal_Context); return restoredDataTable; }
From source file:com.swingtech.commons.util.ClassUtil.java
public static Object deserializeObject(final byte[] bytes) { ObjectInputStream in = null; Object obj = null;//from w w w. jav a 2s.c o m if (bytes == null) { return null; } try { in = new ObjectInputStream(new ByteArrayInputStream(bytes)); obj = in.readObject(); in.close(); } catch (final Exception e) { throw new RuntimeException("Error trying to deserializeObject from this byte array: " + bytes, e); } return obj; }
From source file:SystemUtils.java
public static Object LoadObject(String filePath) throws IOException, ClassNotFoundException { Object target = null;// www .j a v a 2 s . c o m FileInputStream fis = null; ObjectInputStream ois = null; try { fis = new FileInputStream(filePath); ois = new ObjectInputStream(fis); target = ois.readObject(); } finally { if (ois != null) { try { ois.close(); } catch (Exception e) { } ois = null; } if (fis != null) { try { fis.close(); } catch (Exception e) { } fis = null; } } return target; }
From source file:com.gwtquickstarter.server.Deferred.java
/** * Deserialize an object from a byte array. Does not throw any exceptions; * instead, exceptions are logged and null is returned. * * @param bytesIn A byte array containing a previously serialized object. * @return An object instance, or null if an exception occurred. *///from w w w . j a v a2s . c om private static Object deserialize(byte[] bytesIn) { ObjectInputStream objectIn = null; try { if (isDevelopment()) { // workaround for issue #2097 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.conwet.silbops.model.JSONvsRMIPerfT.java
public static void desJSONizeAdvs(ByteArrayInputStream bais, int nElements) { long start = 0, end = 0; try {// w ww . ja v a 2s. c o m ObjectInputStream inputStream = new ObjectInputStream(bais); JSONParser parser = new JSONParser(); start = System.nanoTime(); for (int i = 0; i < nElements; i++) { String jsonReceived = (String) inputStream.readObject(); JSONArray jSONObject = (JSONArray) parser.parse(jsonReceived); Advertise.fromJSON(jSONObject); } end = System.nanoTime(); } catch (Exception ex) { ex.printStackTrace(); } long elapsed = end - start; long elapsedPerMessage = elapsed / nElements; System.out.println(" Elapsed Time " + nElements + " messages - DesJSONize: " + elapsed + " nanoseconds (" + elapsedPerMessage + " nanoseconds/msg)"); }
From source file:com.conwet.silbops.model.JSONvsRMIPerfT.java
public static void desJSONizeSubscriptions(ByteArrayInputStream bais, int nElements) { long start = 0, end = 0; try {//from ww w .j a v a2 s .c o m ObjectInputStream inputStream = new ObjectInputStream(bais); JSONParser parser = new JSONParser(); start = System.nanoTime(); for (int i = 0; i < nElements; i++) { String jsonReceived = (String) inputStream.readObject(); JSONObject jSONObject = (JSONObject) parser.parse(jsonReceived); Subscription.fromJSON(jSONObject); } end = System.nanoTime(); } catch (Exception ex) { ex.printStackTrace(); } long elapsed = end - start; long elapsedPerMessage = elapsed / nElements; System.out.println(" Elapsed Time " + nElements + " messages - DesJSONize: " + elapsed + " nanoseconds (" + elapsedPerMessage + " nanoseconds/msg)"); }
From source file:com.conwet.silbops.model.JSONvsRMIPerfT.java
public static void desJSONizeNots(ByteArrayInputStream bais, int nElements) { long start = 0, end = 0; try {/* ww w . j a va2 s .c om*/ ObjectInputStream inputStream = new ObjectInputStream(bais); JSONParser parser = new JSONParser(); start = System.nanoTime(); for (int i = 0; i < nElements; i++) { String jsonReceived = (String) inputStream.readObject(); JSONObject jSONObject = (JSONObject) parser.parse(jsonReceived); Notification.fromJSON(jSONObject); } end = System.nanoTime(); } catch (Exception ex) { ex.printStackTrace(); } long elapsed = end - start; long elapsedPerMessage = elapsed / nElements; System.out.println(" Elapsed Time " + nElements + " messages - DesJSONize: " + elapsed + " nanoseconds (" + elapsedPerMessage + " nanoseconds/msg)"); }
From source file:com.newatlanta.appengine.taskqueue.Deferred.java
/** * Deserialize an object from a byte array. Does not throw any exceptions; * instead, exceptions are logged and null is returned. * * @param bytesIn A byte array containing a previously serialized object. * @return An object instance, or null if an exception occurred. *//* w ww . j a v a 2 s.co m*/ private static Object deserialize(byte[] bytesIn) { ObjectInputStream objectIn = null; try { // if ( isDevelopment() ) { // workaround for issue #2097 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) { } } }