Search in sources :

Example 26 with ObjectInputStream

use of java.io.ObjectInputStream in project mybatis-3 by mybatis.

the class SerializableProxyTest method deserialize.

protected Serializable deserialize(byte[] value) throws Exception {
    ByteArrayInputStream bis = new ByteArrayInputStream(value);
    ObjectInputStream ois = new ObjectInputStream(bis);
    Serializable result = (Serializable) ois.readObject();
    ois.close();
    return result;
}
Also used : Serializable(java.io.Serializable) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 27 with ObjectInputStream

use of java.io.ObjectInputStream in project XobotOS by xamarin.

the class SimpleDateFormat method readObject.

private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
    ObjectInputStream.GetField fields = stream.readFields();
    int version = fields.get("serialVersionOnStream", 0);
    Date date;
    if (version > 0) {
        date = (Date) fields.get("defaultCenturyStart", new Date());
    } else {
        date = new Date();
    }
    set2DigitYearStart(date);
    formatData = (DateFormatSymbols) fields.get("formatData", null);
    pattern = (String) fields.get("pattern", "");
}
Also used : Date(java.util.Date) ObjectInputStream(java.io.ObjectInputStream)

Example 28 with ObjectInputStream

use of java.io.ObjectInputStream in project OpenAM by OpenRock.

the class IOUtils method deserialise.

/**
     * Deserialises an object from a byte array to an object of a specified type.
     *
     * @param bytes The bytes that represent the Object to be deserialized. The classes to be loaded must be from the
     *              set specified in the whitelist maintained in the <code>WhitelistObjectInputStream</code>
     * @param compressed If true, expect that the bytes are compressed.
     * @param classLoader Used in place of the default ClassLoader, default will be used if null.
     * @param <T> The returned object type.
     * @return The Object T representing the deserialized bytes
     * @throws IOException If there was a problem with the ObjectInputStream process.
     * @throws ClassNotFoundException If there was problem loading a class that makes up the bytes to be deserialized.
     */
public static <T> T deserialise(byte[] bytes, boolean compressed, ClassLoader classLoader) throws IOException, ClassNotFoundException {
    final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    final ObjectInputStream ois = compressed ? new WhitelistObjectInputStream(new InflaterInputStream(bais), classLoader) : new WhitelistObjectInputStream(bais, classLoader);
    final T result;
    try {
        result = (T) ois.readObject();
    } finally {
        closeIfNotNull(ois);
    }
    return result;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 29 with ObjectInputStream

use of java.io.ObjectInputStream in project OpenAM by OpenRock.

the class GrammarInfoImpl method getGrammar.

/**
     * Gets the MSV AGM which can be used to validate XML during
     * marshalling/unmarshalling.
     */
public final com.sun.msv.grammar.Grammar getGrammar() throws JAXBException {
    try {
        InputStream is = objectFactoryClass.getResourceAsStream("bgm.ser");
        if (is == null) {
            // unable to find bgm.ser
            String name = objectFactoryClass.getName();
            int idx = name.lastIndexOf('.');
            name = '/' + name.substring(0, idx + 1).replace('.', '/') + "bgm.ser";
            throw new JAXBException(Messages.format(Messages.NO_BGM, name));
        }
        // deserialize the bgm
        ObjectInputStream ois = new ObjectInputStream(is);
        com.sun.xml.bind.GrammarImpl g = (com.sun.xml.bind.GrammarImpl) ois.readObject();
        ois.close();
        // connect to itself
        g.connect(new com.sun.msv.grammar.Grammar[] { g });
        return g;
    } catch (Exception e) {
        throw new JAXBException(Messages.format(Messages.UNABLE_TO_READ_BGM), e);
    }
}
Also used : ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) JAXBException(javax.xml.bind.JAXBException) JAXBException(javax.xml.bind.JAXBException) ObjectInputStream(java.io.ObjectInputStream)

Example 30 with ObjectInputStream

use of java.io.ObjectInputStream in project android_frameworks_base by ResurrectionRemix.

the class RationalTest method deserialize.

private static <T extends Serializable> T deserialize(byte[] array, Class<T> klass) throws IOException, ClassNotFoundException {
    ByteArrayInputStream bais = new ByteArrayInputStream(array);
    ObjectInputStream ois = new ObjectInputStream(bais);
    Object obj = ois.readObject();
    return klass.cast(obj);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ObjectInputStream (java.io.ObjectInputStream)2159 ByteArrayInputStream (java.io.ByteArrayInputStream)1406 ObjectOutputStream (java.io.ObjectOutputStream)970 ByteArrayOutputStream (java.io.ByteArrayOutputStream)807 IOException (java.io.IOException)752 Test (org.junit.Test)458 FileInputStream (java.io.FileInputStream)339 File (java.io.File)197 InputStream (java.io.InputStream)157 ArrayList (java.util.ArrayList)90 BufferedInputStream (java.io.BufferedInputStream)84 Serializable (java.io.Serializable)66 FileNotFoundException (java.io.FileNotFoundException)64 FileOutputStream (java.io.FileOutputStream)63 HashMap (java.util.HashMap)63 Socket (java.net.Socket)49 Map (java.util.Map)48 ObjectInput (java.io.ObjectInput)45 GZIPInputStream (java.util.zip.GZIPInputStream)44 List (java.util.List)37