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:cn.lynx.emi.license.ViewLicense.java

public static final LicenseBean retrieveLicense(String license) throws UnsupportedEncodingException {
    String decryptedLicense = _decrypt(license);
    try {//ww  w  .j  a va 2s  . c o m
        ObjectInputStream ois = new ObjectInputStream(
                new ByteArrayInputStream(Base64.decodeBase64(decryptedLicense)));
        LicenseBean bean = (LicenseBean) ois.readObject();
        return bean;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:jp.queuelinker.system.util.SerializeUtil.java

/**
 * Deserializes an object from a byte array by using the Java standard serialization mechanism.
 * @param data/*from w ww  .  j  ava2s  .  com*/
 * @param offset
 * @param length
 * @return
 */
public static Object deserialize(final byte[] data, final int offset, final int length) {
    Object ret = null;
    ByteArrayInputStream byteStream = new ByteArrayInputStream(data, offset, length);

    try {
        ObjectInputStream objStream = new ObjectInputStream(byteStream);
        ret = objStream.readObject();
        objStream.close();
    } catch (IOException e) {
        logger.error("Exception: " + e);
    } catch (ClassNotFoundException e) {
        logger.error("Exception: " + e);
    }
    return ret;
}

From source file:Test.java

private static void serverStart() {
    try {/*from  ww  w .j  av a2s.com*/
        InetSocketAddress hostAddress = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 2583);
        AsynchronousServerSocketChannel serverSocketChannel = AsynchronousServerSocketChannel.open()
                .bind(hostAddress);
        Future<AsynchronousSocketChannel> serverFuture = serverSocketChannel.accept();
        final AsynchronousSocketChannel clientSocket = serverFuture.get();
        if ((clientSocket != null) && (clientSocket.isOpen())) {
            InputStream connectionInputStream = Channels.newInputStream(clientSocket);
            ObjectInputStream ois = null;
            ois = new ObjectInputStream(connectionInputStream);
            while (true) {
                Object object = ois.readObject();
                if (object.equals("EOF")) {
                    clientSocket.close();
                    break;
                }
                System.out.println("Received :" + object);
            }
            ois.close();
            connectionInputStream.close();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.canoo.webtest.boundary.StreamBoundary.java

public static Object tryReadObject(final ObjectInputStream ois, final Step step) throws IOException {
    try {/* ww w  .  j  a  va 2 s  .  c o  m*/
        return ois.readObject();
    } catch (ClassNotFoundException e) {
        LOG.error(e.getMessage(), e);
        throw new StepExecutionException("Error reading object from file: " + e.getMessage(), step);
    }
}

From source file:Util.java

/**
 * Reads a serialized object from a file that has been compressed using gzip.
 *  You probably want to use {@link #readObject} instead, because it will automatically guess
 *  from the extension whether the file is compressed, and call this method if necessary.
 * @param f Compressed file to read object from
 * @see #readObject/*from w  ww  .j av  a2 s  .  c  o  m*/
 */
public static Object readGzippedObject(File f) {
    try {
        ObjectInputStream ois = new ObjectInputStream(
                new BufferedInputStream(new GZIPInputStream(new FileInputStream(f))));
        Object obj = ois.readObject();
        ois.close();
        return obj;
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}

From source file:conceptnet.ConceptBuilder.java

public static Concept readConcept(String name) {
    Concept c = null;//from w w w  . j  a  v  a  2 s . c  om
    String path = conceptPath + name;
    File f = new File(path);
    if (!f.exists() || f.isDirectory()) {
        return null;
    }
    try {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f));
        c = (Concept) (ois.readObject());
        ois.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return c;
}

From source file:de.kbs.acavis.service.SerializationHelper.java

public static AuthorIdentifier deserializeAuthorIdentifier(String serialization)
        throws IOException, ClassNotFoundException {
    byte b[] = serialization.getBytes();

    ByteArrayInputStream bi = new ByteArrayInputStream(b);
    ObjectInputStream si = new ObjectInputStream(bi);

    AuthorIdentifier identifier = (AuthorIdentifier) si.readObject();

    si.close();//from   www.j  av  a  2s  .  c  o  m
    bi.close();

    return identifier;
}

From source file:Main.java

private static Object bytes2Object(final byte[] bytes) {
    if (bytes == null)
        return null;
    ObjectInputStream ois = null;
    try {//  w ww  .  j  av a 2  s .com
        ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
        return ois.readObject();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        try {
            if (ois != null) {
                ois.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:gnomezgrave.gsyncj.auth.Profile.java

public static Profile loadProfileSettings(String fileName) throws IOException, ClassNotFoundException {
    ObjectInputStream oi = new ObjectInputStream(new FileInputStream(fileName));
    Profile profile = (Profile) oi.readObject();
    oi.close();/* w  w  w .  j av a 2 s .  co  m*/
    return profile;
}

From source file:com.moz.fiji.hive.utils.FijiDataRequestSerializer.java

/**
 * Deserializes a data request.//from  w  w  w.j  a  v a  2s .  c om
 *
 * @param serialized A serialized data request.
 * @return A data request, or null if there is no data request in the given string.
 * @throws IOException If there is an IO error.
 */
public static FijiDataRequest deserialize(String serialized) throws IOException {
    final byte[] bytes = Base64.decodeBase64(serialized);
    final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
    try {
        return (FijiDataRequest) ois.readObject();
    } catch (ClassNotFoundException e) {
        throw new IOException(e);
    } finally {
        IOUtils.closeQuietly(ois);
    }
}