List of usage examples for java.io ByteArrayInputStream ByteArrayInputStream
public ByteArrayInputStream(byte buf[])
From source file:Main.java
public static List<String> getNodeValues(String response, String tagName) throws ParserConfigurationException, SAXException { try {//from w w w. j av a2 s . c om DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new ByteArrayInputStream(response.getBytes())); Element rootElement = document.getDocumentElement(); List<String> arrayList = new ArrayList<>(); NodeList list = rootElement.getElementsByTagName(tagName); NodeList subList; if (list != null && list.getLength() > 0) { for (int k = 0; k < list.getLength(); k++) { subList = list.item(k).getChildNodes(); if (subList != null && subList.getLength() > 0) { arrayList.add(subList.item(0).getNodeValue()); } } return arrayList; } } catch (Exception e) { return null; } return null; }
From source file:com.eviware.soapui.impl.wsdl.support.CompressedStringSupport.java
public static String getString(CompressedStringConfig compressedStringConfig) { synchronized (compressedStringConfig) { String compression = compressedStringConfig.getCompression(); if ("gzip".equals(compression)) { try { byte[] bytes = Base64.decodeBase64(compressedStringConfig.getStringValue().getBytes()); GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(bytes)); return Tools.readAll(in, -1).toString(); } catch (IOException e) { SoapUI.logError(e);//w w w . j a v a 2 s. c om } } return compressedStringConfig.getStringValue(); } }
From source file:org.apache.jetspeed.util.Base64.java
public static byte[] decodeAsByteArray(String b64string) throws Exception { InputStream in = MimeUtility.decode(new ByteArrayInputStream(b64string.getBytes()), "base64"); ByteArrayOutputStream out = new ByteArrayOutputStream(); while (true) { int b = in.read(); if (b == -1) break; else/*from w w w . j av a 2 s . c o m*/ out.write(b); } return out.toByteArray(); }
From source file:net.ontopia.utils.EncryptionUtils.java
/** * INTERNAL: Reads the file into memory, encrypting it in the * process, then writes the encrypted data back out to the file. */// w ww.j a v a2s. c o m public static void encrypt(File file) throws IOException { FileInputStream in = new FileInputStream(file); ByteArrayOutputStream tmpout = new ByteArrayOutputStream(); encrypt(in, tmpout); in.close(); FileOutputStream out = new FileOutputStream(file); ByteArrayInputStream src = new ByteArrayInputStream(tmpout.toByteArray()); IOUtils.copy(src, out); out.close(); }
From source file:Main.java
public static Source getDomSourceIgnoringDtd(String xmlContents) throws ParserConfigurationException, SAXException, IOException { InputStream inputStream = new ByteArrayInputStream(xmlContents.getBytes()); Source source = getDomSourceIgnoringDtd(inputStream); return source; }
From source file:es.caib.sgtsic.util.DataHandlers.java
public static DataHandler byteArrayToDataHandler(byte[] arrayByte) { InputStream is = new BufferedInputStream(new ByteArrayInputStream(arrayByte)); String mimetype = ""; try {//from www . j a va2 s . c om mimetype = URLConnection.guessContentTypeFromStream(is); } catch (IOException ex) { Logger.getLogger(DataHandlers.class.getName()).log(Level.SEVERE, null, ex); } DataSource dataSource = new ByteArrayDataSource(arrayByte, mimetype); return new DataHandler(dataSource); }
From source file:Main.java
public static Document toXmlDoc(String xml) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try {/*from w w w.j a v a 2 s .c om*/ DocumentBuilder builder = factory.newDocumentBuilder(); InputStream is = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); return builder.parse(is); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.energyos.espi.common.test.FixtureFactory.java
public static InputStream newUsagePointInputStream(UUID uuid) throws IOException { return new ByteArrayInputStream(newUsagePointXML(uuid).getBytes()); }
From source file:Main.java
/** Returns an input stream based on the specified string * @param string the string which should be converted into an input stream * @return An input stream of the specified string, or null if a problem occurred * @throws UnsupportedEncodingException */ public static InputStream convertStringToInputStream(String string) throws UnsupportedEncodingException { return new ByteArrayInputStream(string.getBytes("UTF-8")); }
From source file:com.oprisnik.semdroid.app.parser.manifest.AXMLConverter.java
public static String getManifestString(byte[] apk) { String result = null;//from ww w.j a va 2 s . c o m ZipInputStream zis = null; ByteArrayInputStream fis = null; try { fis = new ByteArrayInputStream(apk); zis = new ZipInputStream(fis); for (ZipEntry entry = zis.getNextEntry(); entry != null; entry = zis.getNextEntry()) { if (entry.getName().equals("AndroidManifest.xml")) { result = getManifestString(zis); break; } } } catch (FileNotFoundException e) { IOUtils.closeQuietly(fis); } catch (IOException e) { } finally { IOUtils.closeQuietly(zis); } return result; }