List of usage examples for java.io ByteArrayInputStream ByteArrayInputStream
public ByteArrayInputStream(byte buf[])
From source file:Main.java
/** * * @param xml//from ww w. j a v a 2s.c o m * @return * @throws SAXException * @throws ParserConfigurationException * @throws IOException */ public static Document bytesToDom(byte[] xml) throws SAXException, ParserConfigurationException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new ByteArrayInputStream(xml)); }
From source file:com.zyd.ztools.util.XmlUtil.java
public static Property parseXml(String content) { if (content == null || content.length() <= 0) { return null; }//from www.ja v a 2 s . c o m Property property = null; try { Digester digester = new Digester(); digester.clear(); digester.setValidating(false); digester.setUseContextClassLoader(true); digester.addObjectCreate("property", Property.class); digester.addBeanPropertySetter("property/returncode", "returncode"); digester.addBeanPropertySetter("property/key", "key"); digester.addBeanPropertySetter("property/original", "original"); InputStream in = new ByteArrayInputStream(content.getBytes("UTF-8")); property = (Property) digester.parse(in); } catch (Exception e) { System.out.println("?XML..."); System.out.println(content); } return property; }
From source file:Main.java
public static Source createSource(final String message, final String charFormat) throws IOException { StreamSource source = new StreamSource(); byte[] msgByte = message.getBytes(charFormat); ByteArrayInputStream in = new ByteArrayInputStream(msgByte); source.setInputStream(in);/*from w ww .j av a 2 s . c om*/ return source; }
From source file:com.formkiq.core.util.Zips.java
/** * Extract Zip file to Map.//from w ww . j a va2 s . c o m * @param bytes byte[] * @return {@link Map} * @throws IOException IOException */ public static Map<String, byte[]> extractZipToMap(final byte[] bytes) throws IOException { Map<String, byte[]> map = new HashMap<>(); ByteArrayInputStream is = new ByteArrayInputStream(bytes); ZipInputStream zipStream = new ZipInputStream(is); try { ZipEntry entry = null; while ((entry = zipStream.getNextEntry()) != null) { String filename = entry.getName(); byte[] data = IOUtils.toByteArray(zipStream); map.put(filename, data); } } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(zipStream); } return map; }
From source file:cfa.vo.interop.EncodeDoubleArray.java
private static double[] byteToDouble(byte[] data) throws IOException { int len = data.length; if (len % WORDSIZE != 0) { throw new IOException("Array length is not divisible by wordsize"); }/* ww w. j a va2 s .c o m*/ int size = len / WORDSIZE; double[] result = new double[size]; DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(data)); try { int ii = 0; while (inputStream.available() > 0) { result[ii] = inputStream.readDouble(); ii++; } } catch (EOFException e) { throw new IOException("Unable to read from dataInputStream, found EOF"); } catch (IOException e) { throw new IOException("Unable to read from dataInputStream, IO error"); } return result; }
From source file:com.aestasit.markdown.BaseTest.java
protected static InputStream allTestData() throws IOException { ByteArrayOutputStream data = new ByteArrayOutputStream(); for (String fileName : allTestFiles()) { IOUtils.write(IOUtils.toString(testData(fileName)), data); }//ww w . j av a2 s.c om IOUtils.closeQuietly(data); return new ByteArrayInputStream(data.toByteArray()); }
From source file:almira.weblogic.JndiInjectorTest.java
@BeforeClass public static void init() throws IOException { InputStreamReader reader = new InputStreamReader( new ByteArrayInputStream("p1=v1\np2=v2\np3=v3\n".getBytes())); PROPERTIES.load(reader);//from w ww . j a v a 2 s.com }
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();/*from w w w.jav a2 s . c o m*/ bi.close(); return identifier; }
From source file:scala.c24.demo.java.C24DemoUtils.java
public static Document getDocumentFromString(String xml) throws Exception { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(new ByteArrayInputStream(xml.getBytes())); return document; }
From source file:Main.java
static public Document createDocument(String content, String charset) { try {//from w ww. j a v a 2s .c om InputStream is = new ByteArrayInputStream(content.getBytes(charset)); return getBuilder().parse(is); } catch (Exception e) { throw new RuntimeException(e); } }