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:org.globus.workspace.persistence.ErrorUtil.java

public static Throwable getThrowable(byte[] faultBytes) throws IOException, ClassNotFoundException {

    ByteArrayInputStream bais = null;
    ObjectInputStream ois = null;
    try {/*w  w  w .j a va  2 s .com*/
        bais = new ByteArrayInputStream(faultBytes);
        ois = new ObjectInputStream(bais);
        return (Throwable) ois.readObject();
    } finally {
        if (bais != null) {
            bais.close();
        }
        if (ois != null) {
            ois.close();
        }
    }
}

From source file:org.parosproxy.paros.core.proxy.WithBasicInfrastructureIntegrationTest.java

/**
 * Helper method to set the root certificate for this test.
 * /*w ww .  j av  a2s  .  c  om*/
 * @throws KeyStoreException
 * @throws NoSuchAlgorithmException
 * @throws CertificateException
 * @throws IOException
 * @throws UnrecoverableKeyException
 */
protected static void initializeRootCertificate() throws KeyStoreException, NoSuchAlgorithmException,
        CertificateException, IOException, UnrecoverableKeyException {
    final SslCertificateService service = SslCertificateServiceImpl.getService();
    final byte[] bytes = Base64.decodeBase64(
            "_u3-7QAAAAIAAAABAAAAAQARb3dhc3BfemFwX3Jvb3RfY2EAAAE2LA_eqAAABQIwggT-MA4GCisGAQQBKgIRAQEFAASCBOqboCBB1-ZSxYZqYDwdOLd22xkq1R3-ZJMVlt2ad-SMKGTG52RVHNhAfYYUS14QDwD6LF2TxKuHxKQt-CH2QXGZaRtWNzksTLl50J-irz9l7cDNkS-HI7l3ZLK3Hl8Fr_tx3pi91h1uw9qc5xLl0euLZYDo-bnqtqmrvqzBXS7Th0cDa7IDWWTN1foxoyV-26lc9O_abpcTd8ugJqC5_DoDJ1-yW_eIRT4vqiRl1cxcrZGSrA255O21l1CwBxE3y34HqdQf2eDWpPmVDA5qeLTwUWj_AAeXW574jtjvG42sB1mxk5bhSmp53jGBbQqSh4qgvfsny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kMwXKQL1GEPSb0ZOoxjSbDxOUsDjLHW9A8Xh6JQKYL0lMJ6clplrbaNjwtMIM26xJozpRQwQIDAQABo1MwUTAgBgNVHQ4BAf8EFgQUY7QvhPIV67X8kAxEoQTCoyp3N60wDwYDVR0TAQH_BAUwAwEB_zALBgNVHQ8EBAMCAbYwDwYDVR0lBAgwBgYEVR0lADANBgkqhkiG9w0BAQUFAAOCAQEAX5pQ0Pcgy8lEzK3xJaztS3OjUoI1UhJKIqgQeXujXDowMqCLPFHGeN6uVhi4ktjFuun4sfwLBE7CXACl5ZMUpjArD18qdQKQ6glHJ9HYrxKi0lJM2maYt5rkpAhHI8EHnX5IdsDEr2ihoCQUou1h8gGHIe1a6QkeCD_1VrRfKAdwt6UTE6RyaP6nTyr58IZ6Pdw5EQP3FmtA0yXRVapHodQPpudkS24Lj9cxSrpo_gJBSIb-LHpl81TVZg0SAROikcDk69qZDgnbQqLPz6WxsZtWcET1ACOqPHovQIPK6utkyOeOLm-uJL3Iqx84b4yQqnFkG-y-nlDmNWR33DOtE8rTqmBfifcjGibDbx0z26ogkB6I");
    final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    final KeyStore rootca = KeyStore.getInstance(KeyStore.getDefaultType());
    rootca.load(bais, "0w45P.Z4p".toCharArray());
    bais.close();
    service.initializeRootCA(rootca);
}

From source file:com.amalto.workbench.utils.FileProvider.java

public static IFile createdTempFile(String templateString, String fileNameWithExtension, String charSet) {
    IFile file = null;//from  ww  w. ja  v  a  2 s.  c  o  m
    if (templateString != null) {
        try {
            Project project = ProjectManager.getInstance().getCurrentProject();
            IProject prj = ResourceUtils.getProject(project);
            file = prj.getFile(new Path("temp/" + fileNameWithExtension)); //$NON-NLS-1$

            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            OutputStreamWriter outputStreamWriter = null;
            if ((charSet == null) || (charSet.trim().isEmpty())) {
                outputStreamWriter = new OutputStreamWriter(outputStream);
            } else {
                outputStreamWriter = new OutputStreamWriter(outputStream, charSet);
            }

            outputStreamWriter.write(templateString);
            outputStreamWriter.flush();
            outputStreamWriter.close();

            ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
            if (file.exists()) {
                file.setContents(inputStream, true, false, null);
            } else {
                file.create(inputStream, true, null);
            }

            inputStream.close();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

    return file;
}

From source file:org.apache.cloudstack.framework.jobs.impl.JobSerializerHelper.java

public static Object fromObjectSerializedString(String base64EncodedString) {
    if (base64EncodedString == null)
        return null;

    byte[] content = Base64.decodeBase64(base64EncodedString);
    ByteArrayInputStream bs = new ByteArrayInputStream(content);
    try {/*from   w w  w  .  j  a v  a2  s.  com*/
        ObjectInputStream is = new ObjectInputStream(bs);
        Object obj = is.readObject();
        is.close();
        bs.close();
        return obj;
    } catch (IOException e) {
        throw new CloudRuntimeException("Unable to serialize: " + base64EncodedString, e);
    } catch (ClassNotFoundException e) {
        throw new CloudRuntimeException("Unable to serialize: " + base64EncodedString, e);
    }
}

From source file:com.ibm.watson.developer_cloud.professor_languo.ingestion.indexing.StackExchangeThreadSerializer.java

/**
 * reproduce the Java Object with the byte array
 * /*from  w  w  w.  j a va 2s .  com*/
 * @param binCode - the byte array for that Java Object
 * @return the original Java Object before serialization
 * @throws IngestionException
 */
public static Object deserializeObjFromBinArr(byte[] binCode) throws IngestionException {
    Object deserializedObj = null;
    ByteArrayInputStream binIn = new ByteArrayInputStream(binCode);
    try {
        ObjectInputStream in = new ObjectInputStream(binIn);
        deserializedObj = in.readObject();
        in.close();
        binIn.close();
    } catch (IOException | ClassNotFoundException e) {
        throw new IngestionException(e);
    }
    return deserializedObj;
}

From source file:com.ibm.watson.developer_cloud.professor_languo.ingestion.indexing.StackExchangeThreadSerializer.java

/**
 * reproduce the StackExchangeThread with the byte array
 * /*  w  w w . ja  v a  2s.c o  m*/
 * @param binCode - the byte array for that StackExchangeThread
 * @return the original StackExchangeThread before serialization
 * @throws IngestionException
 */
public static StackExchangeThread deserializeThreadFromBinArr(byte[] binCode) throws IngestionException {
    Object deserializedObj = null;
    ByteArrayInputStream binIn = new ByteArrayInputStream(binCode);
    try {
        ObjectInputStream in = new ObjectInputStream(binIn);
        deserializedObj = in.readObject();
        in.close();
        binIn.close();
    } catch (IOException | ClassNotFoundException e) {
        throw new IngestionException(e);
    }
    return (StackExchangeThread) deserializedObj;
}

From source file:jedi.util.serialization.Pickle.java

/**
 * Receives a sequence of bytes and returns a object.
 * //from  w ww  .  j a  v a2s .  c  o  m
 * @param s Sequence of bytes.
 * @return Object
 */
public static Object loads(String s) {
    Object o = null;
    ByteArrayInputStream bais;

    try {
        bais = new ByteArrayInputStream(Base64.decodeBase64(s.getBytes()));
        ObjectInputStream ois = new ObjectInputStream(bais);

        o = ois.readObject();

        ois.close();
        bais.close();

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return o;
}

From source file:com.taobao.tair.etc.TranscoderUtil.java

public static Object deserialize(byte[] in) {
    Object rv = null;/*from  w  w w. j a v a  2 s. com*/

    try {
        if (in != null) {
            ByteArrayInputStream bis = new ByteArrayInputStream(in);
            ObjectInputStream is = new ObjectInputStream(bis);

            rv = is.readObject();
            is.close();
            bis.close();
        }
    } catch (Exception e) {
        throw new RuntimeException("deserialize failed", e);
    }

    return rv;
}

From source file:org.apache.rocketmq.jms.support.MessageConverter.java

public static Serializable objectDeserialize(byte[] bytes) throws IOException, ClassNotFoundException {
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    ObjectInputStream ois = new ObjectInputStream(bais);
    ois.close();/*from   w ww  .  j  ava2  s . c  om*/
    bais.close();
    return (Serializable) ois.readObject();
}

From source file:com.db.comserv.main.utilities.HttpCaller.java

public static String compress(String imageString, float quality) throws IOException {
    byte[] imageByte = Base64.decodeBase64(imageString);
    ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
    BufferedImage image = ImageIO.read(bis);
    bis.close();

    // Get a ImageWriter for given extension format.

    Iterator<ImageWriter> writers = ImageIO.getImageWritersBySuffix("jpg");
    if (!writers.hasNext())
        throw new IllegalStateException("No writers found");

    ImageWriter writer = (ImageWriter) writers.next();
    // Create the ImageWriteParam to compress the image.
    ImageWriteParam param = writer.getDefaultWriteParam();
    param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    param.setCompressionQuality(quality);

    // The output will be a ByteArrayOutputStream (in memory)
    ByteArrayOutputStream bos = new ByteArrayOutputStream(32768);
    ImageOutputStream ios = ImageIO.createImageOutputStream(bos);
    writer.setOutput(ios);/*from   w  w  w . j a  va  2 s.  c  om*/
    writer.write(null, new IIOImage(image, null, null), param);
    ios.flush(); // otherwise the buffer size will be zero!
    byte[] encodedBytes = Base64.encodeBase64(bos.toByteArray());

    return new String(encodedBytes);
}