List of usage examples for java.io ByteArrayInputStream ByteArrayInputStream
public ByteArrayInputStream(byte buf[])
From source file:Main.java
public static List copyBySerialize(List src) throws IOException, ClassNotFoundException { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(byteOut); out.writeObject(src);/* ww w . java 2 s . c o m*/ ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray()); ObjectInputStream in = new ObjectInputStream(byteIn); List dest = (List) in.readObject(); return dest; }
From source file:Main.java
/** * Compress a String to a zip file that has only one entry like zipName * The name shouldn't have .zip//from w w w. j ava 2 s. c om * * @param content * @param fName * @throws IOException */ public static void zipAContentAsFileName(String fName, String content, String charset) throws IOException { ByteArrayInputStream bais = new ByteArrayInputStream(content.getBytes(charset)); BufferedInputStream bis = new BufferedInputStream(bais); File f = new File(fName); File parentFile = f.getParentFile(); if (!parentFile.exists()) { parentFile.mkdirs(); } ZipOutputStream zf = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(f + ".zip"))); ZipEntry entry = new ZipEntry(f.getName()); zf.putNextEntry(entry); byte[] barr = new byte[8192]; int len = 0; while ((len = bis.read(barr)) != -1) { zf.write(barr, 0, len); } zf.flush(); zf.close(); bis.close(); bais.close(); }
From source file:Main.java
public static Document noPrefixDomObjcet(StringBuffer data) throws SAXException, IOException, ParserConfigurationException { Document xmlDoc = null;//from ww w. ja v a 2s.co m xmlDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(new ByteArrayInputStream(data.toString().getBytes())); return xmlDoc; }
From source file:Main.java
public static InputStream convertToInputStream(Bitmap bitmap) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); byte[] imageInByte = stream.toByteArray(); System.out.println("........length......" + imageInByte); ByteArrayInputStream bis = new ByteArrayInputStream(imageInByte); return bis;/*from w ww .j a v a 2s .c o m*/ }
From source file:Main.java
public static InputStream toCompressedJpeg(Bitmap bitmap) { ByteArrayOutputStream thumbnailBytes = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.JPEG, 85, thumbnailBytes); return new ByteArrayInputStream(thumbnailBytes.toByteArray()); }
From source file:Main.java
public static void writeBytes(OutputStream destination, byte[] data) throws IOException { transfer(new ByteArrayInputStream(data), destination); }
From source file:Main.java
public static Object xml2BeanUtf8(Class<?> zClass, String xml) { Object obj = null;//from www. j a va 2s . c om JAXBContext context = null; if (null == xml || "".equals(xml) || "null".equalsIgnoreCase(xml) || xml.length() < 1) return obj; try { context = JAXBContext.newInstance(zClass); InputStream iStream = new ByteArrayInputStream(xml.getBytes("UTF-8")); Unmarshaller um = context.createUnmarshaller(); obj = (Object) um.unmarshal(iStream); return obj; } catch (Exception e) { e.printStackTrace(); } return obj; }
From source file:Main.java
public static <T> List<T> deepCopy(List<T> src) throws IOException, ClassNotFoundException { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(byteOut); out.writeObject(src);// www. j av a 2s. c o m ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray()); ObjectInputStream in = new ObjectInputStream(byteIn); @SuppressWarnings("unchecked") List<T> dest = (List<T>) in.readObject(); return dest; }
From source file:Main.java
/** * TODO Finish JavaDoc// w w w. jav a 2s . co m * * @param byteArray * @return */ public static String decompress(byte[] byteArray) { StringBuilder stringBuilder = new StringBuilder(); String line; try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader( new GZIPInputStream(new ByteArrayInputStream(byteArray)), StandardCharsets.UTF_8))) { while ((line = bufferedReader.readLine()) != null) { stringBuilder.append(line); } } catch (IOException e) { e.printStackTrace(); } return stringBuilder.toString(); }
From source file:Main.java
public static Object convertToPojoUsingString(String xml, Class... type) { Object result;// www . j av a 2 s .co m try { JAXBContext context = JAXBContext.newInstance(type); Unmarshaller unmarshaller = context.createUnmarshaller(); InputStream stream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); result = unmarshaller.unmarshal(stream); } catch (JAXBException e) { throw new RuntimeException(e); } return result; }