Example usage for java.io ByteArrayInputStream ByteArrayInputStream

List of usage examples for java.io ByteArrayInputStream ByteArrayInputStream

Introduction

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

Prototype

public ByteArrayInputStream(byte buf[]) 

Source Link

Document

Creates a ByteArrayInputStream so that it uses buf as its buffer array.

Usage

From source file:Main.java

public static Bitmap compressImage(Bitmap image) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    image.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    int options = 100;
    while (baos.toByteArray().length / 1024 > 100) {
        options -= 10;// w  w  w.j a v  a2  s  .  com
        if (options > 0) {
            baos.reset();
            image.compress(Bitmap.CompressFormat.JPEG, options, baos);
        }
    }
    ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());
    return BitmapFactory.decodeStream(isBm, null, null);
}

From source file:org.energyos.espi.common.test.FixtureFactory.java

public static InputStream newFeedInputStream() throws IOException {
    return new ByteArrayInputStream(newXML("/fixtures/test_usage_data.xml").getBytes());
}

From source file:Main.java

public static String toHTML(String xml) throws TransformerException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    StreamResult result = new StreamResult(baos);
    xmlToHTMLTransformer.transform(new StreamSource(new ByteArrayInputStream(xml.getBytes())), result);
    return baos.toString();
}

From source file:Main.java

public static Document transformStringToDoc(String input) throws ParserConfigurationException, Exception {
    ByteArrayInputStream bais = new ByteArrayInputStream(input.getBytes());
    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
    return doc;//from w  w  w.ja va2 s .  c  o m
}

From source file:Main.java

public synchronized static Document loadDocument(String data)
        throws SAXException, IOException, ParserConfigurationException {
    if (data != null && !data.isEmpty()) {
        return loadDocument(new ByteArrayInputStream(data.getBytes("UTF-8")));
    }/*from  ww w. ja v a 2  s  .c  o  m*/
    return null;
}

From source file:Main.java

public static X509Certificate base64StringToCertificate(String certificateString)
        throws CertificateException, IOException {

    if (certificateString == null) {
        throw new IllegalArgumentException("certificateString cannot be null");
    }/*from w  w  w .j av  a2 s  .co  m*/

    byte[] encodedCert = Base64.decode(certificateString, Base64.DEFAULT);
    InputStream inStream = new ByteArrayInputStream(encodedCert);
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    X509Certificate cert = (X509Certificate) cf.generateCertificate(inStream);
    inStream.close();

    return cert;
}

From source file:Main.java

public static Bitmap compressBmpFromBmp(Bitmap image) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int options = 100;
    image.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    while (baos.toByteArray().length / 1024 > 100) {
        baos.reset();// w  w w  .j av a2 s.c  o m
        options -= 10;
        image.compress(Bitmap.CompressFormat.JPEG, options, baos);
    }
    ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());
    Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null);
    return bitmap;
}

From source file:com.eviware.loadui.impl.statistics.db.util.TypeConverter.java

public static BufferedImage imageFromByteArray(byte[] imagebytes) throws IOException {
    if (imagebytes != null && (imagebytes.length > 0)) {
        return ImageIO.read(new ByteArrayInputStream(imagebytes));
    }/*  www.j a  v  a 2 s. c o m*/
    return null;
}

From source file:Main.java

/** Read an XML document from a String */
public static Document readXmlDocumentFromString(String xml) throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setIgnoringElementContentWhitespace(true);
    dbf.setCoalescing(true);/*from  w w  w  .j av a 2  s  .  co m*/
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(new ByteArrayInputStream(xml.getBytes()));
    return doc;
}

From source file:Main.java

private static Document readString(String xmlSource)
        throws IOException, SAXException, ParserConfigurationException {
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    return docBuilder.parse(new ByteArrayInputStream(xmlSource.getBytes(StandardCharsets.UTF_8)));
}