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:Main.java

public static Document LoadXml(String xml) throws Exception {
    // create...//from www  .  j  a v  a2s .  co  m
    ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes());
    try {
        return LoadXml(stream);
    } finally {
        if (stream != null)
            stream.close();
    }
}

From source file:Main.java

public static Object getSerializable(byte[] bytes) {
    Object obj = null;/*ww w .  j  av a2 s  . com*/
    try {
        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(bis);
        obj = ois.readObject();
        ois.close();
        bis.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    } catch (ClassNotFoundException ex) {
        ex.printStackTrace();
    }
    return obj;
}

From source file:com.reydentx.core.common.JSONUtils.java

private static BufferedImage decodeToImage(String imageString) {
    BufferedImage image = null;// ww  w. j  a  v  a 2  s  .  com
    byte[] imageByte;
    try {
        imageByte = Base64.decodeBase64(imageString);
        ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
        image = ImageIO.read(bis);
        bis.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return image;
}

From source file:org.meveo.admin.util.ModuleUtil.java

public static void writePicture(String filename, byte[] fileData) throws Exception {
    ByteArrayInputStream in = new ByteArrayInputStream(fileData);
    BufferedImage img = ImageIO.read(in);
    in.close();
    ImageIO.write(img, filename.substring(filename.indexOf(".") + 1), new File(filename));
}

From source file:Main.java

public static Object toObject(byte[] bytes) {
    Object obj = null;/*  w  w w .j  a v a 2s . com*/
    try {
        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(bis);
        obj = ois.readObject();
        ois.close();
        bis.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return obj;
}

From source file:ch.fork.AdHocRailway.ui.utils.ImageTools.java

/**
 * Decode string to image//from   w ww  . ja  v  a2  s.co m
 *
 * @param imageString The string to decode
 * @return decoded image
 */
public static BufferedImage decodeToImage(String imageString) {

    BufferedImage image = null;
    byte[] imageByte;
    try {
        imageByte = Base64.decodeBase64(imageString);
        ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
        image = ImageIO.read(bis);
        bis.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return image;
}

From source file:Main.java

/**
 * Creates a {@link Node} out of a {@link String}
 * /*  w  ww  .j a v  a2 s .com*/
 * @param xmlString
 *            never <code>null</code>
 * @return the string as node, never <code>null</code>
 */
public static Node asNode(String xmlString) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    ByteArrayInputStream is = new ByteArrayInputStream(xmlString.getBytes());
    try {
        Document wfsCapabilities = builder.parse(is);
        return wfsCapabilities.getDocumentElement();
    } finally {
        is.close();
    }
}

From source file:com.github.khandroid.http.misc.FileDownloader.java

public static void download(HttpClient httpClient, URI source, File destination)
        throws ClientProtocolException, IOException {
    byte[] content = download(httpClient, source);
    ByteArrayInputStream input = new ByteArrayInputStream(content);
    BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(destination));

    IOUtils.copy(input, output);//from  ww w  .j a v a 2s.  c  o  m
    input.close();
    output.close();
}

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//from   ww w  .j a v a 2 s.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 stringToElement(String xml) throws Exception {
    ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes("utf8"));
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document d = builder.parse(bais);
    bais.close();
    return d.getDocumentElement();
}

From source file:org.opennms.netmgt.charts.ChartUtilsTest.java

private static void initalizeChartFactory() throws MarshalException, ValidationException, IOException {
    ChartConfigFactory.setInstance(new ChartConfigFactory());
    ByteArrayInputStream rdr = new ByteArrayInputStream(CHART_CONFIG.getBytes("UTF-8"));
    ChartConfigFactory.parseXml(rdr);//w  ww  .j  a  va2  s .  co m
    rdr.close();
    //        m_config = ChartConfigFactory.getInstance().getConfiguration();
}