List of usage examples for java.io ByteArrayInputStream ByteArrayInputStream
public ByteArrayInputStream(byte buf[])
From source file:Main.java
public static InputStream Bitmap2InputStream(Bitmap bm, int quality) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.PNG, quality, baos); InputStream is = new ByteArrayInputStream(baos.toByteArray()); return is;/* w w w . j a v a 2 s .c o m*/ }
From source file:Main.java
public static InputStream getInputStreamFromBitmap(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); InputStream isBm = new ByteArrayInputStream(baos.toByteArray()); return isBm;// w w w . java 2 s . com }
From source file:Main.java
/** Read the object from Base64 string. */ public static Object fromString(String s) throws IOException, ClassNotFoundException { byte[] data = Base64.decode(s, 0); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data)); Object o = ois.readObject();//from w w w .j av a 2s .c o m ois.close(); return o; }
From source file:Main.java
public static InputStream Bitmap2IS(Bitmap bm) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); // What about 50... bm.compress(Bitmap.CompressFormat.JPEG, 50, baos); InputStream sbs = new ByteArrayInputStream(baos.toByteArray()); return sbs;// w w w. ja va2 s . co m }
From source file:Main.java
public static InputStream getStringStream(String sInputString) throws UnsupportedEncodingException { ByteArrayInputStream tInputStringStream = null; if (sInputString != null && !sInputString.trim().equals("")) { tInputStringStream = new ByteArrayInputStream(sInputString.getBytes("UTF-8")); }// ww w . jav a 2s . c om return tInputStringStream; }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> Object xmlToObject(String xmlContent, Class<T> clazz) throws JAXBException { ByteArrayInputStream xmlContentBytes = new ByteArrayInputStream(xmlContent.getBytes()); JAXBContext context = JAXBContext.newInstance(clazz); Unmarshaller unmarshaller = context.createUnmarshaller(); unmarshaller.setSchema(null); //note: setting schema to null will turn validator off Object unmarshalledObj = unmarshaller.unmarshal(xmlContentBytes); Object xmlObject = clazz.cast(unmarshalledObj); return (T) xmlObject; }
From source file:Main.java
public static InputStream Bitmap2IS(Bitmap bm) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.JPEG, 70, baos); InputStream sbs = new ByteArrayInputStream(baos.toByteArray()); return sbs;/*w w w. java 2 s . c o m*/ }
From source file:Main.java
public static Object xmlStrToObj(String inputStr, Class inputClass) throws Exception { byte[] byteArray = inputStr.getBytes(); ByteArrayInputStream byteStream = new ByteArrayInputStream(byteArray); XMLInputFactory input = XMLInputFactory.newFactory(); XMLStreamReader reader = input.createXMLStreamReader(byteStream); JAXBContext context = JAXBContext.newInstance(inputClass); Unmarshaller unmarsh = context.createUnmarshaller(); Object result = unmarsh.unmarshal(reader); return result; }
From source file:Main.java
/** * Deserialize an array of bytes into an object. * @param input Serialized stream of bytes * @return Deserialized object./*from w ww . j a v a 2 s. c om*/ * @throws IOException * @throws ClassNotFoundException */ public static Serializable bytesToObject(byte input[]) throws IOException, ClassNotFoundException { return (Serializable) new ObjectInputStream(new ByteArrayInputStream(input)).readObject(); }
From source file:Main.java
public static InputStream bitmap2InputStream(Bitmap bm) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.PNG, 100, baos); InputStream is = new ByteArrayInputStream(baos.toByteArray()); return is;/*from ww w .j a va 2 s. c o m*/ }