Example usage for java.io ObjectInputStream readObject

List of usage examples for java.io ObjectInputStream readObject

Introduction

In this page you can find the example usage for java.io ObjectInputStream readObject.

Prototype

public final Object readObject() throws IOException, ClassNotFoundException 

Source Link

Document

Read an object from the ObjectInputStream.

Usage

From source file:com.marintek.isis.wicket.popupbox.applib.PopupWicketBoxSemanticsProvider.java

static Object fromString(String s) {
    final byte[] data = Base64.decodeBase64(s);
    ObjectInputStream ois = null;
    try {/* ww w . j a  v a2 s.  com*/
        ois = new ObjectInputStream(new ByteArrayInputStream(data));
        return ois.readObject();
    } catch (IOException e) {
        throw new Base64Serializer.Exception(e);
    } catch (ClassNotFoundException e) {
        throw new Base64Serializer.Exception(e);
    } finally {
        try {
            if (ois != null) {
                ois.close();
            }
        } catch (IOException e) {
            throw new Base64Serializer.Exception(e);
        }
    }
}

From source file:com.textocat.textokit.morph.opencorpora.resource.DictionaryDeserializer.java

public static MorphDictionaryImpl from(InputStream in, String srcLabel) throws Exception {
    log.info("About to deserialize MorphDictionary from InputStream of {}...", srcLabel);
    long timeBefore = currentTimeMillis();
    InputStream is = new BufferedInputStream(in, DICTIONARY_READING_BUFFER_SIZE);
    ObjectInputStream ois = new ObjectInputStream(is);
    MorphDictionaryImpl dict;//from   w w  w.j a  v a  2 s.  c o  m
    try {
        // skip gram model
        @SuppressWarnings("unused")
        GramModel gm = (GramModel) ois.readObject();
        dict = (MorphDictionaryImpl) ois.readObject();
    } finally {
        IOUtils.closeQuietly(ois);
    }
    log.info("Deserialization of MorphDictionary finished in {} ms", currentTimeMillis() - timeBefore);
    return dict;
}

From source file:fr.inria.atlanmod.neoemf.data.hbase.util.HBaseEncoderUtil.java

public static String[] toStrings(byte[] bytes) {
    if (isNull(bytes)) {
        return null;
    }/* w w w .  j  av a  2 s.c  o m*/

    String[] result = null;
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
    ObjectInputStream objectInputStream = null;
    try {
        objectInputStream = new ObjectInputStream(byteArrayInputStream);
        result = (String[]) objectInputStream.readObject();
    } catch (IOException e) {
        NeoLogger.error("Unable to convert ''{0}'' to String[]", Arrays.toString(bytes));
    } catch (ClassNotFoundException e) {
        NeoLogger.error(e);
    } finally {
        IOUtils.closeQuietly(objectInputStream);
    }
    return result;
}

From source file:org.nebulaframework.util.io.IOSupport.java

/**
 * Deserializes an object instance from the given byte[] 
 * of serial data.//  www  .  j  a  va 2s.  c o m
 * 
 * @param bytes Byte[] containing serialized data
 * 
 * @return Deserialized object
 * 
 * @throws IOException if thrown during serialization
 */
@SuppressWarnings("unchecked") // Ignore type casting Warnings
public static <T extends Serializable> T deserializeFromBytes(byte[] bytes)
        throws IOException, ClassNotFoundException {

    Assert.notNull(bytes);

    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
    return (T) ois.readObject();
}

From source file:com.ecyrd.jspwiki.util.Serializer.java

/**
 * Deserializes a Base64-encoded String into a HashMap. Both the keys and values
 * must implement {@link java.io.Serializable}.
 * @param rawString the String contents containing the map to be deserialized
 * @return the attributes, parsed into a Map
 * @throws IOException if the contents cannot be parsed for any reason
 *//*w  ww .  j  a  va  2  s. co  m*/
@SuppressWarnings("unchecked")
public static Map<String, ? extends Serializable> deserializeFromBase64(String rawString) throws IOException {
    // Decode from Base64-encoded String to byte array
    byte[] decodedBytes = Base64.decodeBase64(rawString.getBytes("UTF-8"));

    // Deserialize from the input stream to the Map
    InputStream bytesIn = new ByteArrayInputStream(decodedBytes);
    ObjectInputStream in = new ObjectInputStream(bytesIn);
    HashMap<String, Serializable> attributes;
    try {
        attributes = (HashMap<String, Serializable>) in.readObject();
    } catch (ClassNotFoundException e) {
        throw new IOException("Could not deserialiaze user profile attributes. Reason: " + e.getMessage());
    } finally {
        in.close();
    }
    return attributes;
}

From source file:license.rsa.WakeRSA.java

/**
 * ?/*from   w w w  .  j a  va2 s. co m*/
 * 
 * @param keyFileName
 * @return
 * @throws Exception
 */
static PublicKey readPublicKeyFromFile() throws Exception {
    ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(KeyData.publicKey));
    try {
        BigInteger m = (BigInteger) oin.readObject();
        BigInteger e = (BigInteger) oin.readObject();
        System.out.println();
        System.out.println();
        System.out.println("=======mmm=====" + m);
        System.out.println("=======eeee=====" + e);
        System.out.println();
        System.out.println();
        RSAPublicKeySpec keySpec = new RSAPublicKeySpec(m, e);
        KeyFactory fact = KeyFactory.getInstance("RSA");
        return fact.generatePublic(keySpec);
    } finally {
        oin.close();
    }
}

From source file:Main.java

public static Object getAsObject(String key) {
    byte[] data = getAsBinary(key);
    if (data != null) {
        ByteArrayInputStream bais = null;
        ObjectInputStream ois = null;
        try {// www  . ja va2  s.c  o  m
            bais = new ByteArrayInputStream(data);
            ois = new ObjectInputStream(bais);
            Object reObject = ois.readObject();
            return reObject;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            try {
                if (bais != null)
                    bais.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                if (ois != null)
                    ois.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return null;
}

From source file:com.talis.storage.s3.cache.RedisChunkHandler.java

public static S3Object deserialize(byte[] bytes) {
    try {//from  ww  w  . j av  a2  s  . co  m
        ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes);
        ObjectInputStream objStream = new ObjectInputStream(byteStream);
        return (S3Object) objStream.readObject();
    } catch (Exception e) {
        LOG.warn("Exception parsing cached bytes");
        return null;
    }
}

From source file:com.oprisnik.semdroid.utils.FileUtils.java

public static Object loadObjectFromStream(InputStream input) throws ClassNotFoundException, IOException {
    ObjectInputStream ois = null;
    Object obj = null;//from  ww w.j  a  v  a2s  . co m
    try {
        ois = new ObjectInputStream(input);
        obj = ois.readObject();
    } finally {
        IOUtils.closeQuietly(ois);
    }
    return obj;
}

From source file:com.vico.license.util.rsa.RSAdoDecrypt.java

public static String decrypt(String cryptograph) throws Exception {
    Key privateKey;/*from  w  ww. j a  v a 2  s  .  co  m*/
    String path = Thread.currentThread().getContextClassLoader().getResource("/").toURI().getPath();
    ObjectInputStream ois = null;
    try {
        /** ? */
        ois = new ObjectInputStream(new FileInputStream(path + FileNames.PRIVATEKEY_NAME));
        privateKey = (Key) ois.readObject();
    } catch (Exception e) {
        throw e;
    } finally {
        ois.close();
    }

    /** Cipher?RSA */
    Cipher cipher = Cipher.getInstance(ALGORITHM);
    cipher.init(Cipher.DECRYPT_MODE, privateKey);

    /** ? */
    byte[] b1 = Base64.decodeBase64(cryptograph);
    /** ? */
    byte[] b = cipher.doFinal(b1);
    return new String(b);
}