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 String validateAgainstXSD(String xml, String xsd) throws IOException {

    InputStream isXml = new ByteArrayInputStream(xml.getBytes());
    InputStream isXsd = new ByteArrayInputStream(xsd.getBytes());

    return isXmlPassingSchemaValidation(isXml, isXsd);
}

From source file:Main.java

/**
 * convert Bitmap to InputStream/*w  w w.jav  a  2s  .c  om*/
 */
public static InputStream bitmapToStream(Bitmap bitmap, Bitmap.CompressFormat compressFormat) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bitmap.compress(compressFormat, 100, bos);
    return new ByteArrayInputStream(bos.toByteArray());
}

From source file:Main.java

public static org.w3c.dom.Document readXML(String xmlString) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);//from  w w  w.j a  va  2 s .  c  o  m
    DocumentBuilder builder = factory.newDocumentBuilder();
    return builder.parse(new ByteArrayInputStream(xmlString.getBytes()));
}

From source file:Main.java

public static Document parseXml(String xml) {
    try {/*  ww w.java 2s  .  c  om*/
        DocumentBuilder dBuilder = getDocumentBuilder();
        return dBuilder.parse(new ByteArrayInputStream(xml.getBytes("UTF-8")));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static InputStream bitmap2Ins(Bitmap bm) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(CompressFormat.JPEG, 100, baos);
    InputStream sbs = new ByteArrayInputStream(baos.toByteArray());
    return sbs;/*from  w ww.  j  av a2s.  co  m*/
}

From source file:Main.java

public static boolean validProcess(String xml) {
    try {//from   w  ww  .  j  a v  a2 s .c  o m
        Set<String> classifiers = new HashSet<String>();

        InputStream is = new ByteArrayInputStream(xml.getBytes());
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
        Document document = docBuilder.parse(is);

        // iterate over all operators
        NodeList nodes = document.getElementsByTagName("operator");
        for (int i = 0; i < nodes.getLength(); i++) {
            Element element = (Element) nodes.item(i);
            String className = element.getAttribute("class");

            if (classifiers.contains(className)) {
                return false;
            }
            classifiers.add(className);
        }
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:Main.java

public static <T> Object fromXml(String xmlStr, Class<T> pojoClass) throws JAXBException {
    JAXBContext jaxbContext = JAXBContext.newInstance(pojoClass);
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    Object object = unmarshaller.unmarshal(new ByteArrayInputStream(xmlStr.getBytes()));
    return object;
}

From source file:Main.java

public static String decompress(byte[] bytes) {
    if (bytes == null || bytes.length == 0) {
        return "";
    }//from  w w  w .  ja  v  a  2 s .  c  o m
    String outStr = "";
    try {
        final GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(bytes));
        final BufferedReader bf = new BufferedReader(new InputStreamReader(gis, "UTF-8"));
        String line;
        while ((line = bf.readLine()) != null) {
            outStr += line;
        }
        bf.close();
    } catch (final IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return outStr;
}

From source file:Main.java

public static X509Certificate unserializeCert(String cert) throws CertificateException {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    InputStream in = new ByteArrayInputStream(cert.getBytes());
    return (X509Certificate) cf.generateCertificate(in);
}

From source file:Main.java

public static InputStream getInputStreamFromBitmap(Bitmap bitmap) {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
    final byte[] bitmapdata = out.toByteArray();
    final ByteArrayInputStream bs = new ByteArrayInputStream(bitmapdata);
    return bs;/*from  w  ww .j  a  va  2  s  .  c om*/
}