Example usage for java.io ByteArrayInputStream close

List of usage examples for java.io ByteArrayInputStream close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closing a ByteArrayInputStream has no effect.

Usage

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();// w  w  w .  jav a 2 s.  c  om
    bi.close();

    return identifier;
}

From source file:Main.java

/**
 * Converts a String representing an XML snippet into an {@link org.w3c.dom.Element}.
 *
 * @param xml snippet as a string/* ww w.  j  a  va  2s. c  o  m*/
 *
 * @return a DOM Element
 *
 * @throws Exception if unable to parse the String or if it doesn't contain valid XML.
 */
public static Element elementFromString(String xml) throws Exception {
    ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes("UTF-8"));
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(bais);
    bais.close();
    return document.getDocumentElement();
}

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

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

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

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

    si.close();/* www. j a v a  2s.  c  om*/
    bi.close();

    return identifier;
}

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.
 *//*www  .ja  v  a 2  s  .  co  m*/
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:BytesUtil.java

public static Object toObject(byte[] bytes) throws IOException, ClassNotFoundException {
    Object obj = null;//w w  w. ja  va2s  .  co  m
    ByteArrayInputStream bis = null;
    ObjectInputStream ois = null;
    try {
        bis = new ByteArrayInputStream(bytes);
        ois = new ObjectInputStream(bis);
        obj = ois.readObject();
    } finally {
        if (bis != null) {
            bis.close();
        }
        if (ois != null) {
            ois.close();
        }
    }
    return obj;
}

From source file:Main.java

static byte[] decompress(byte[] compressed) throws IOException {
    int nRead;/*w  w  w  . j  a v  a 2 s  .  c  o  m*/
    byte[] data = new byte[2048];
    ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
    GZIPInputStream gzip = new GZIPInputStream(bis);
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();

    while ((nRead = gzip.read(data, 0, data.length)) != -1) {
        buffer.write(data, 0, nRead);
    }

    bis.close();
    gzip.close();
    return buffer.toByteArray();
}

From source file:Main.java

private static String bytesToString(byte[] bytes) {
    if (bytes == null) {
        return null;
    }/*w w w  . j  a v a2  s. c om*/
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    DataInputStream dis = new DataInputStream(bais);
    String res = "";
    try {
        res = dis.readUTF();
    } catch (IOException ex) {
    } finally {
        try {
            dis.close();
            bais.close();
        } catch (IOException ex1) {
        }
        dis = null;
        bais = null;
    }
    return res;
}

From source file:org.computerist.ssltools.zap.ZapSslCertificateUtils.java

/**
 * @param str/*w ww .j ava2  s. c o m*/
 * @return
 * @throws KeyStoreException
 * @throws IOException
 * @throws CertificateException
 * @throws NoSuchAlgorithmException
 */
public static final KeyStore string2Keystore(String str)
        throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
    final byte[] bytes = Base64.decodeBase64(str);
    final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    final KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
    ks.load(bais, FixedSslCertificateService.PASSPHRASE);
    bais.close();
    return ks;
}

From source file:com.pinterest.terrapin.zookeeper.ViewInfo.java

public static ViewInfo fromCompressedJson(byte[] compressedJson) throws Exception {
    ByteArrayInputStream in = new ByteArrayInputStream(compressedJson);
    GZIPInputStream zipIs = new GZIPInputStream(in);
    ViewInfo viewInfo = fromJson(IOUtils.toByteArray(zipIs));
    in.close();
    zipIs.close();/*www.j a  v a 2s.  c om*/
    return viewInfo;
}

From source file:Main.java

static byte[] decompress(byte[] compressed) throws IOException {
    int nRead;//  ww w  .  java 2  s  . c  om
    byte[] data = new byte[2048];
    ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
    GZIPInputStream gzip = new GZIPInputStream(bis);
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();

    while ((nRead = gzip.read(data, 0, data.length)) != -1) {
        buffer.write(data, 0, nRead);
    }

    gzip.close();
    bis.close();
    return buffer.toByteArray();
}