List of usage examples for java.io ObjectInputStream ObjectInputStream
public ObjectInputStream(InputStream in) throws IOException
From source file:com.hurence.logisland.processor.hbase.util.ObjectSerDe.java
@Override public Object deserialize(InputStream is) throws DeserializationException, IOException { if (is == null) { return null; }//from w w w . j av a2 s . c o m byte[] input = IOUtils.toByteArray(is); if (input == null || input.length == 0) { return null; } try (final ByteArrayInputStream in = new ByteArrayInputStream(input); final ObjectInputStream objIn = new ObjectInputStream(in)) { return objIn.readObject(); } catch (ClassNotFoundException e) { throw new DeserializationException("Could not deserialize object due to ClassNotFoundException", e); } }
From source file:com.openteach.diamond.network.waverider.master.MasterState.java
public static MasterState fromByteBuffer(ByteBuffer buffer) { ByteArrayInputStream bin = null; ObjectInputStream oin = null; try {// w w w. j a v a2s .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:com.thoughtworks.go.websocket.MessageEncoding.java
public static Work decodeWork(String data) { try {/*w w w .ja v a2 s. co m*/ byte[] binary = Base64.getDecoder().decode(data.getBytes(StandardCharsets.UTF_8)); try (ObjectInputStream objectStream = new ObjectInputStream(new ByteArrayInputStream(binary))) { return (Work) objectStream.readObject(); } } catch (ClassNotFoundException | IOException e) { throw bomb(e); } }
From source file:corner.util.crypto.Cryptor.java
/** * IO?,IO??,.//from w w w. jav a 2 s.c o m * @param outFileName ??. * @param keyFile ??. * @return ??. */ public static OutputStream encryptFileIO(String outFileName, String keyFile) { if (keyFile == null) { try { return new FileOutputStream(outFileName); } catch (FileNotFoundException e) { throw new RuntimeException(e); } } SecretKey key = null; //? ObjectInputStream keyis; try { keyis = new ObjectInputStream(new FileInputStream(keyFile)); key = (SecretKey) keyis.readObject(); keyis.close(); } catch (FileNotFoundException e) { log.error("file not found!", e); throw new RuntimeException("file not found", e); } catch (IOException e) { log.error("io occour exception", e); throw new RuntimeException(e); } catch (ClassNotFoundException e) { log.error("Class Not Found exception", e); throw new RuntimeException(e); } //keyCipher Cipher cipher = null; //?Cipher? try { cipher = Cipher.getInstance("DES"); //? cipher.init(Cipher.ENCRYPT_MODE, key); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } catch (NoSuchPaddingException e) { throw new RuntimeException(e); } catch (InvalidKeyException e) { throw new RuntimeException(e); } //??? // CipherOutputStream out = null; try { out = new CipherOutputStream(new BufferedOutputStream(new FileOutputStream(outFileName)), cipher); } catch (FileNotFoundException e) { throw new RuntimeException(e); } return out; }
From source file:com.yahoo.bullet.record.AvroBulletRecordTest.java
public static AvroBulletRecord fromRecordBytes(byte[] data) { try {/*from ww w .jav a2s . co m*/ ObjectInputStream stream = new ObjectInputStream(new ByteArrayInputStream(data)); return (AvroBulletRecord) stream.readObject(); } catch (IOException | ClassNotFoundException e) { throw new RuntimeException(e); } }
From source file:aot.util.IOUtil.java
public static Object deserialize(byte[] data) { try (ByteArrayInputStream buffer = new ByteArrayInputStream(data)) { try (ObjectInputStream input = new ObjectInputStream(buffer)) { return input.readObject(); }/*from w w w . ja v a 2s.co m*/ } catch (Exception e) { throw new RuntimeException(e); } }
From source file:cz.seznam.euphoria.hadoop.SerializableWritableTest.java
@SuppressWarnings("unchecked") @Test/*w w w .ja va 2s . c o m*/ public void testSerialization() throws Exception { Configuration conf = new Configuration(); conf.set("key", "value"); SerializableWritable<Configuration> sw = new SerializableWritable<>(conf); // clone by serialization ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(sw); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); sw = (SerializableWritable<Configuration>) ois.readObject(); Configuration newConf = sw.getWritable(); assertEquals(conf.get("key"), newConf.get("key")); }
From source file:de.tudarmstadt.ukp.dkpro.core.frequency.tfidf.util.TfidfUtils.java
@SuppressWarnings("unchecked") public static <T> T deserialize(String filePath) throws Exception { ObjectInputStream in = null;//www . j av a 2 s . c o m try { in = new ObjectInputStream(new FileInputStream(new File(filePath))); return (T) in.readObject(); } finally { closeQuietly(in); } }
From source file:de.dfki.asr.compass.model.AbstractCompassEntity.java
public AbstractCompassEntity deepCopy() throws IOException, ClassNotFoundException { AbstractCompassEntity entity = null; forceEagerFetch();// w ww .j av a 2 s. co m // Write the object out to a byte array ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bos); out.writeObject(this); out.flush(); out.close(); // Make an input stream from the byte array and read // a copy of the object back in. ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray())); entity = (AbstractCompassEntity) in.readObject(); entity.clearIdsAfterDeepCopy(); return entity; }
From source file:com.googlecode.osde.internal.utils.MapUtil.java
public static Map<String, String> toMap(String data) throws IOException, ClassNotFoundException { if (StringUtils.isNotBlank(data)) { byte[] bytes = data.getBytes("UTF-8"); byte[] decoded = Base64.decodeBase64(bytes); ByteArrayInputStream bais = new ByteArrayInputStream(decoded); ObjectInputStream in = new ObjectInputStream(bais); @SuppressWarnings("unchecked") Map<String, String> result = (Map<String, String>) in.readObject(); return result; }//from w w w . j a v a2s . c o m return new HashMap<String, String>(); }