/** Serializes and deserializes the specified object. */ @SuppressWarnings("unchecked") static <T> T reserialize(T object) { checkNotNull(object); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); try { ObjectOutputStream out = new ObjectOutputStream(bytes); out.writeObject(object); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray())); return (T) in.readObject(); } catch (IOException | ClassNotFoundException e) { throw new RuntimeException(e); } }
public boolean open(InputStream stream) { try { ObjectInputStream ois = new ObjectInputStream(stream); int version = (Integer) ois.readObject(); costFactor_ = (Double) ois.readObject(); maxid_ = (Integer) ois.readObject(); xsize_ = (Integer) ois.readObject(); y_ = (List<String>) ois.readObject(); unigramTempls_ = (List<String>) ois.readObject(); bigramTempls_ = (List<String>) ois.readObject(); dat = (MutableDoubleArrayTrieInteger) ois.readObject(); alpha_ = (double[]) ois.readObject(); ois.close(); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
@SuppressWarnings("unchecked") private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); init(DEFAULT_SIZE, DEFAULT_LOAD_FACTOR); int elementCount = stream.readInt(); for (int i = elementCount; --i >= 0; ) { K key = (K) stream.readObject(); V value = (V) stream.readObject(); put(key, value); } } }
/** * Prints out the pair of {@code Extractors} objects found in the * file that is the first and only argument. * @param args Filename of extractors file (standardly written with * {@code .ex} extension) */ public static void main(String[] args) { try { ObjectInputStream in = new ObjectInputStream(new FileInputStream(args[0])); Extractors extrs = (Extractors) in.readObject(); Extractors extrsRare = (Extractors) in.readObject(); in.close(); System.out.println("All words: " + extrs); System.out.println("Rare words: " + extrsRare); } catch (Exception e) { throw new RuntimeException(e); } }
public static KerberosTicket deserializeKerberosTicket(byte[] tgtBytes) { KerberosTicket ret; try { ByteArrayInputStream bin = new ByteArrayInputStream(tgtBytes); ObjectInputStream in = new ObjectInputStream(bin); ret = (KerberosTicket) in.readObject(); in.close(); } catch (Exception e) { throw new RuntimeException(e); } return ret; }
private static Bug1234 writeRead(final Bug1234 original) { try { final ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(fileName)); outputStream.writeObject(original); outputStream.close(); final ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(fileName)); final Bug1234 result = (Bug1234)inputStream.readObject(); inputStream.close(); return result; } catch (final Throwable e) { throw new RuntimeException("Error: " + e); } }
try { FileInputStream e = new FileInputStream("outings.ser"); ObjectInputStream inputStream = new ObjectInputStream(e); return (ArrayList)inputStream.readObject(); } catch (ClassNotFoundException | IOException var3) { var3.printStackTrace(); } return null;
/** * Deserialize the byte array into an object. * @param bytes a serialized object * @return the result of deserializing the bytes */ @Nullable public static Object deserialize(@Nullable byte[] bytes) { if (bytes == null) { return null; } try { ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes)); return ois.readObject(); } catch (IOException ex) { throw new IllegalArgumentException("Failed to deserialize object", ex); } catch (ClassNotFoundException ex) { throw new IllegalStateException("Failed to deserialize object type", ex); } }
public static Object deserialize(InputStream inputStream) throws IOException, ClassNotFoundException { try (ObjectInputStream objectInputStream = new ObjectInputStream(inputStream)) { return objectInputStream.readObject(); } }
@Override protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { ByteBuf frame = (ByteBuf) super.decode(ctx, in); if (frame == null) { return null; } ObjectInputStream ois = new CompactObjectInputStream(new ByteBufInputStream(frame, true), classResolver); try { return ois.readObject(); } finally { ois.close(); } } }
@SuppressWarnings("unchecked") static <T> T reserialize(T object) { try { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bytes); out.writeObject(object); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray())); return (T) in.readObject(); } catch (IOException | ClassNotFoundException e) { Helpers.fail(e, e.getMessage()); } throw new AssertionError("not reachable"); }
public static Object deserialize(String filePath) throws Exception { FileInputStream fis = new FileInputStream(filePath); ObjectInputStream ois = new ObjectInputStream(fis); Object obj = ois.readObject(); ois.close(); fis.close(); return obj; }
ByteArrayInputStream bais = new ByteArrayInputStream(bytes); GZIPInputStream gzipIn = new GZIPInputStream(bais); ObjectInputStream objectIn = new ObjectInputStream(gzipIn); MyObject myObj1 = (MyObject) objectIn.readObject(); MyObject myObj2 = (MyObject) objectIn.readObject(); objectIn.close();
Map map = new HashMap(); map.put("1",new Integer(1)); map.put("2",new Integer(2)); map.put("3",new Integer(3)); FileOutputStream fos = new FileOutputStream("map.ser"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(map); oos.close(); FileInputStream fis = new FileInputStream("map.ser"); ObjectInputStream ois = new ObjectInputStream(fis); Map anotherMap = (Map) ois.readObject(); ois.close(); System.out.println(anotherMap);
public static <T> DoubleArrayTrie<T> unSerialize(String path) { ObjectInputStream in; try { in = new ObjectInputStream(IOAdapter == null ? new FileInputStream(path) : IOAdapter.open(path)); return (DoubleArrayTrie<T>) in.readObject(); } catch (Exception e) { // e.printStackTrace(); return null; } }
public static Session deserialize(String sessionStr) { if (StringUtils.isBlank(sessionStr)) { return null; } try { ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decode(sessionStr)); ObjectInputStream ois = new ObjectInputStream(bis); return (Session) ois.readObject(); } catch (Exception e) { throw new RuntimeException("deserialize session error", e); } }
@GwtIncompatible // java.io.ObjectInputStream @SuppressWarnings("unchecked") // reading data stored by writeObject private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); factory = (Supplier<? extends List<V>>) stream.readObject(); Map<K, Collection<V>> map = (Map<K, Collection<V>>) stream.readObject(); setMap(map); }
FileInputStream fis = context.openFileInput(fileName); ObjectInputStream is = new ObjectInputStream(fis); SimpleClass simpleClass = (SimpleClass) is.readObject(); is.close(); fis.close();
@Override protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { ByteBuf frame = (ByteBuf) super.decode(ctx, in); if (frame == null) { return null; } ObjectInputStream ois = new CompactObjectInputStream(new ByteBufInputStream(frame, true), classResolver); try { return ois.readObject(); } finally { ois.close(); } } }
public static byte[] serialize(Object obj) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutputStream os = new ObjectOutputStream(out); os.writeObject(obj); return out.toByteArray(); } public static Object deserialize(byte[] data) throws IOException, ClassNotFoundException { ByteArrayInputStream in = new ByteArrayInputStream(data); ObjectInputStream is = new ObjectInputStream(in); return is.readObject(); }