List of usage examples for java.io ObjectInputStream readObject
public final Object readObject() throws IOException, ClassNotFoundException
From source file:Main.java
public static Stroke readStroke(ObjectInputStream in) throws IOException, ClassNotFoundException { boolean wroteStroke = in.readBoolean(); if (wroteStroke) { boolean serializedStroke = in.readBoolean(); if (serializedStroke) { return (Stroke) in.readObject(); } else {/* w w w . j av a2s. co m*/ float[] dash = null; int dashLength = in.read(); if (dashLength != 0) { dash = new float[dashLength]; for (int i = 0; i < dashLength; i++) { dash[i] = in.readFloat(); } } float lineWidth = in.readFloat(); int endCap = in.readInt(); int lineJoin = in.readInt(); float miterLimit = in.readFloat(); float dashPhase = in.readFloat(); return new BasicStroke(lineWidth, endCap, lineJoin, miterLimit, dash, dashPhase); } } else { return null; } }
From source file:gov.nih.nci.ncicb.cadsr.bulkloader.ui.CommandLineUserInterfaceImpl.java
private static UserInput getSerializedInput() { UserInput userInput = null;//ww w . java2 s .c o m try { File serFile = new File(SERIALIZE_FILE_NAME); if (!serFile.exists()) { return new UserInput(); } FileInputStream fis = new FileInputStream(serFile); ObjectInputStream ois = new ObjectInputStream(fis); Object obj = ois.readObject(); if (obj instanceof UserInput) { userInput = (UserInput) obj; } } catch (Exception e) { log.error("Error de-serializing input", e); } if (userInput == null) { userInput = new UserInput(); } return userInput; }
From source file:com.joliciel.jochre.lexicon.TextFileLexicon.java
public static TextFileLexicon deserialize(ZipInputStream zis) { TextFileLexicon memoryBase = null;//from w ww .j av a 2 s. c o m try { ZipEntry zipEntry; if ((zipEntry = zis.getNextEntry()) != null) { LOG.debug("Scanning zip entry " + zipEntry.getName()); ObjectInputStream in = new ObjectInputStream(zis); memoryBase = (TextFileLexicon) in.readObject(); zis.closeEntry(); in.close(); } else { throw new RuntimeException("No zip entry in input stream"); } } catch (IOException ioe) { throw new RuntimeException(ioe); } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } return memoryBase; }
From source file:net.mindengine.oculus.frontend.web.Auth.java
public static User decodeUser(String encodedString) { try {// ww w. j a va 2s . com ObjectInputStream ois = new ObjectInputStream( new ByteArrayInputStream(Base64.decodeBase64(encodedString.getBytes()))); SealedObject sealedObject = (SealedObject) ois.readObject(); ois.close(); Cipher dcipher = Cipher.getInstance("DES"); dcipher.init(Cipher.DECRYPT_MODE, secrectAuthKey); User user = (User) sealedObject.getObject(dcipher); return user; } catch (Exception e) { return null; } }
From source file:berlin.iconn.persistence.InOutOperations.java
public static float[][] loadSimpleWeights(File file) throws IOException, ClassNotFoundException { ObjectInputStream ois = new ObjectInputStream(Files.newInputStream(file.toPath())); float[][] weights = (float[][]) ois.readObject(); ois.close();//from w w w.j a va2s . c om return weights; }
From source file:net.darkmist.alib.io.Serializer.java
/** Read one serialized object from a input stream. * @param in InputStream to read from. This will be closed! * @param type The type that is to be read. * @return The serialized object cast as type. */// ww w. jav a2 s. co m public static <T extends Serializable> T deserializeFromStream(InputStream in, Class<T> type) throws ClassNotFoundException, IOException { ObjectInputStream objIn; T obj; if (in instanceof ObjectInputStream) objIn = (ObjectInputStream) in; else objIn = new ObjectInputStream(in); obj = type.cast(objIn.readObject()); // to close or not to close... That is the question... // we close... It doesn't make too much sense to have a stream with more afterwards...There would be two // stream headers... objIn.close(); return obj; }
From source file:license.regist.ReadProjectInfo.java
static PublicKey readPublicKeyFromFile() throws Exception { ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(KeyData.publicKey)); try {/*from w w w . j a v a2s . 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:it.polito.elite.dog.core.library.model.DeviceStatus.java
/** * Deserialize a DeviceStatus from a byte encoded String * @param serialization// w w w.j ava 2 s. co m * a byte encoded String of a DeviceStatus * @return a deserialized DeviceStatus * @throws IOException * @throws ClassNotFoundException */ public static DeviceStatus deserializeFromString(String serialization) throws IOException, ClassNotFoundException { byte[] data = Base64.decodeBase64(serialization); ByteArrayInputStream bais = new ByteArrayInputStream(data); ObjectInputStream decoder = new ObjectInputStream(bais); //deserialize the DeviceStatus DeviceStatus o = (DeviceStatus) decoder.readObject(); decoder.close(); return o; }
From source file:org.alfresco.rad.test.AlfrescoTestRunner.java
protected static Object objectFromString(String string) throws IOException, ClassNotFoundException { byte[] buffer = Base64.decodeBase64(string); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(buffer)); Object object = ois.readObject(); ois.close();/* w w w. j a v a 2 s. c o m*/ return object; }
From source file:it.unimi.di.big.mg4j.io.IOFactories.java
public static Object loadObject(final IOFactory ioFactory, final String filename) throws IOException, ClassNotFoundException { final ObjectInputStream ois = new ObjectInputStream( new FastBufferedInputStream(ioFactory.getInputStream(filename))); final Object result = ois.readObject(); ois.close();//from www.j a va 2 s . c o m return result; }