Example usage for java.io ObjectInput close

List of usage examples for java.io ObjectInput close

Introduction

In this page you can find the example usage for java.io ObjectInput close.

Prototype

public void close() throws IOException;

Source Link

Document

Closes the input stream.

Usage

From source file:Main.java

/**
 * Close the specified object input, ignoring any exceptions.
 *//*from   w ww  . ja  v  a2  s  .  c  o  m*/
public static void closeQuietly(ObjectInput objectInput) {
    try {
        objectInput.close();
    } catch (final Exception e) {
        // Ignored
    }
}

From source file:org.codehaus.wadi.core.util.Utils.java

public static Externalizable setContent(Externalizable object, byte[] content, Streamer streamer)
        throws IOException, ClassNotFoundException {
    ByteArrayInputStream bais = new ByteArrayInputStream(content);
    ObjectInput oi = streamer.getInputStream(bais);
    object.readExternal(oi);//w  w  w  .  ja  v a2 s. co m
    oi.close();
    return object;
}

From source file:com.mobicage.rogerthat.mfr.dal.Streamable.java

protected static Object fromBase64(String base64String) {
    try {/*from w  w w  . ja v  a  2 s .c  om*/
        ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decodeBase64(base64String));

        try {
            ZipInputStream zip = new ZipInputStream(bis);
            try {
                zip.getNextEntry();
                ObjectInput in = new ObjectInputStream(zip);
                try {
                    return in.readObject();
                } finally {
                    in.close();
                }
            } finally {
                zip.close();
            }
        } finally {
            bis.close();
        }
    } catch (ClassNotFoundException e) {
        log.log((Level.SEVERE), "ClassNotFoundException while deserializing member", e);
        return null;
    } catch (IOException e) {
        log.log((Level.SEVERE), "IOException while deserializing member", e);
        return null;
    }
}

From source file:org.apache.stratos.autoscaler.util.Deserializer.java

/**
 * Deserialize a byte array and retrieve the object.
 * @param bytes bytes to be deserialized
 * @return the deserialized {@link Object}
 * @throws Exception if the deserialization is failed.
 *///  w w  w.  ja va  2s . c  om
public static Object deserializeFromByteArray(byte[] bytes) throws Exception {

    ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
    ObjectInput in = null;
    try {
        in = new ObjectInputStream(bis);
        Object o = in.readObject();

        return o;

    } finally {
        bis.close();
        if (in != null) {
            in.close();
        }
    }
}

From source file:VASSAL.tools.io.IOUtils.java

/**
 * Close an {@link ObjectInput} unconditionally. Equivalent to
 * calling <code>o.close()</code> when <code>o</code> is nonnull.
 * {@link IOException}s are swallowed, as there is generally
 * nothing that can be done about exceptions on closing.
 *
 * @param o a (possibly <code>null</code>) <code>ObjectInput</code>
 *//*w ww .  j ava  2  s . c  o  m*/
public static void closeQuietly(ObjectInput o) {
    if (o == null)
        return;

    try {
        o.close();
    } catch (IOException e) {
        // ignore
    }
}

From source file:Main.java

/**
 * Convert bytes array to object./* w  ww. j  a  v  a  2  s .  c o m*/
 *
 * @param bytes object bytes
 * @param <T> object class
 * @return object
 */
public static <T> T fromBytes(byte[] bytes) {
    Object result = null;
    ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
    ObjectInput in = null;
    try {
        in = new ObjectInputStream(bis);
        result = in.readObject();
    } catch (IOException | ClassNotFoundException e) {
        throw new RuntimeException(e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (Exception e) {
            }
        }
        if (bis != null) {
            try {
                bis.close();
            } catch (Exception e) {
            }
        }
    }
    return (T) result;
}

From source file:wvec.WordVec.java

static WordVec decodeFromByteArray(BytesRef bytes) throws Exception {
    ObjectInput in;
    Object o;// ww  w.  jav  a  2 s.co  m
    try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes.bytes)) {
        in = new ObjectInputStream(bis);
        o = in.readObject();
    }
    in.close();
    return (WordVec) o;
}

From source file:Main.java

public static Object fromByteArray(byte[] inputBytes) {
    Object obj = null;/*  w  w w. ja  va 2s. c o  m*/
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(inputBytes);
    ObjectInput objIn = null;
    try {
        objIn = new ObjectInputStream(byteArrayInputStream);
        obj = objIn.readObject();
    } catch (java.io.IOException ioe) {
        return null;
    } catch (java.lang.ClassNotFoundException cnfe) {
        return null;
    } finally {
        try {
            byteArrayInputStream.close();
            objIn.close();
        } catch (java.io.IOException closeIOE) {

        }
    }
    return obj;
}

From source file:Main.java

public static Object deserialize(byte[] bytes) {
    ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
    ObjectInput in = null;
    Object o = null;/*from  w w w  . j a v  a2s. c  o  m*/
    try {
        in = new ObjectInputStream(bis);
        o = in.readObject();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            bis.close();
        } catch (IOException ex) {
            // ignore close exception
        }
        try {
            if (in != null) {
                in.close();
            }
        } catch (IOException ex) {
            // ignore close exception
        }
    }
    return o;
}

From source file:com.act.reachables.Network.java

public static Network deserialize(String fromFile) {
    try {//from   ww w. ja v a  2s . c o  m
        InputStream file = new FileInputStream(fromFile);
        InputStream buffer = new BufferedInputStream(file);
        ObjectInput input = new ObjectInputStream(buffer);
        try {
            return (Network) input.readObject();
        } finally {
            input.close();
        }
    } catch (ClassNotFoundException ex) {
        throw new RuntimeException("Network deserialize failed: Class not found: " + ex);
    } catch (IOException ex) {
        throw new RuntimeException("Network deserialize failed: IO problem: " + ex);
    }
}