List of usage examples for java.io ByteArrayInputStream ByteArrayInputStream
public ByteArrayInputStream(byte buf[])
From source file:Main.java
private static InputStream bitmapToStream(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.PNG, 100, baos); InputStream sbs = new ByteArrayInputStream(baos.toByteArray()); return sbs;// www. j ava2s . c o m }
From source file:Main.java
public static InputStream bitmap2InputStream4Gif(Bitmap bm) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.WEBP, 100, baos); InputStream is = new ByteArrayInputStream(baos.toByteArray()); return is;//from ww w . ja v a2 s . c o m }
From source file:Main.java
public static InputStream getInputStream(Bitmap bitmap) { ByteArrayOutputStream bStream = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.JPEG, 100, bStream); return new ByteArrayInputStream(bStream.toByteArray()); }
From source file:Main.java
public static InputStream bitmap2InputStream(Bitmap bm) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); InputStream is = new ByteArrayInputStream(baos.toByteArray()); return is;//from w w w. j a va 2 s . com }
From source file:Main.java
public static boolean hasValidXmlDeclaration(byte[] doc) throws Exception { try {//from www . jav a 2 s . c o m XMLStreamReader r = xif.createXMLStreamReader(new ByteArrayInputStream(doc), null); if (!"UTF-8".equalsIgnoreCase(r.getEncoding())) return false; if (!"1.0".equals(r.getVersion())) return false; r.close(); return true; } catch (XMLStreamException e) { throw new Exception("Unable to parse xml", e); } }
From source file:Main.java
public static byte[] getCompressedImage(byte[] rgb) { BufferedImage image;/*from ww w . ja v a 2s.c om*/ int width; int height; try { image = ImageIO.read(new ByteArrayInputStream(rgb)); width = image.getWidth(); height = image.getHeight(); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Color c = new Color(image.getRGB(j, i)); int red = (int) (c.getRed() * 0.299); int green = (int) (c.getGreen() * 0.587); int blue = (int) (c.getBlue() * 0.114); Color newColor = new Color(red + green + blue, red + green + blue, red + green + blue); image.setRGB(j, i, newColor.getRGB()); } } ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "jpg", baos); baos.flush(); byte[] imageInByte = baos.toByteArray(); baos.close(); return imageInByte; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static List String2SceneList(String SceneListString) throws IOException, ClassNotFoundException { byte[] mobileBytes = Base64.decode(SceneListString.getBytes(), Base64.DEFAULT); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(mobileBytes); ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream); List SceneList = (List) objectInputStream.readObject(); objectInputStream.close();//from w w w . j a va 2s . c o m return SceneList; }
From source file:Main.java
public static InputStream bitmap2InputStream(Bitmap bm, Bitmap.CompressFormat format, int quality) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(format, quality, baos);/*w w w .j av a2 s.c o m*/ InputStream is = new ByteArrayInputStream(baos.toByteArray()); return is; }
From source file:Main.java
public static Element parseElement(String xml) { try {//from w w w.ja va2s . c o m DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); Document doc = docBuilder.parse(new ByteArrayInputStream(xml.getBytes())); return doc.getDocumentElement(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:Main.java
public static Element byteArrayToElement(byte[] cont) { if (cont == null || cont.length <= 0) return null; try {/*from www.j a v a 2 s .c om*/ ByteArrayInputStream bais = new ByteArrayInputStream(cont); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setNamespaceAware(false); docBuilderFactory.setValidating(false); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); InputSource is = new InputSource(bais); // is.setEncoding("gb2312"); Document doc = docBuilder.parse(is); return doc.getDocumentElement(); } catch (Exception e) { e.printStackTrace(); return null; } }