List of usage examples for java.io ByteArrayInputStream ByteArrayInputStream
public ByteArrayInputStream(byte buf[])
From source file:Main.java
public static Object byteToObject(byte[] data) throws IOException, ClassNotFoundException { ByteArrayInputStream inputStream = new ByteArrayInputStream(data); ObjectInputStream is = new ObjectInputStream(inputStream); return is.readObject(); }
From source file:Main.java
public static Object StringToObject(String str) throws Exception { byte[] data = Base64.decode(str, 0); ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(data)); Object object = objectInputStream.readObject(); objectInputStream.close();//from ww w . ja v a 2 s . com return object; }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> T deserializeFromByteArray(byte[] bytes) { if (bytes == null) { return null; }/*from w ww . j av a 2 s . c om*/ ByteArrayInputStream bais = new ByteArrayInputStream(bytes); T object = null; try { ObjectInputStream ois = new ObjectInputStream(bais); object = (T) ois.readObject(); } catch (Exception e) { e.printStackTrace(); return null; } return object; }
From source file:Main.java
public static Object convertFromBytes(byte[] bytes) throws IOException, ClassNotFoundException { try {/* ww w . j ava 2s. c o m*/ ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInput in = new ObjectInputStream(bis); return in.readObject(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static Object deserializeObject(byte[] b) { try {/*from w w w .j ava 2 s. c om*/ ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(b)); Object object = in.readObject(); in.close(); return object; } catch (ClassNotFoundException cnfe) { // Log.e("deserializeObject", "class not found error", cnfe); return null; } catch (IOException ioe) { // Log.e("deserializeObject", "io error", ioe); return null; } }
From source file:Main.java
public static Object ByteToObject(byte[] bytes) { ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInput in = null;/* w ww.ja v a2 s . c o m*/ try { in = new ObjectInputStream(bis); } catch (StreamCorruptedException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Object obj = null; try { obj = in.readObject(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return obj; }
From source file:Main.java
public static Object getSerializable(byte[] bytes) { Object obj = null;/*from www. jav a 2s. c o m*/ try { ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bis); obj = ois.readObject(); ois.close(); bis.close(); } catch (IOException ex) { ex.printStackTrace(); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } return obj; }
From source file:Main.java
public static Object getObject(byte[] bytes) throws IOException, ClassNotFoundException { ByteArrayInputStream bi = new ByteArrayInputStream(bytes); ObjectInputStream oi = new ObjectInputStream(bi); Object obj = oi.readObject(); bi.close();/* w ww . j a v a 2s.co m*/ oi.close(); return obj; }
From source file:Main.java
public static InputStream stringToInputStream(String str, String code) { if (TextUtils.isEmpty(code)) { return new ByteArrayInputStream(str.getBytes()); } else {//from ww w . j av a 2s . c om try { return new ByteArrayInputStream(str.getBytes(code)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return new ByteArrayInputStream(str.getBytes()); } } }
From source file:Main.java
public static InputStream toStream(ByteBuffer bytebuffer) { byte abyte0[] = new byte[bytebuffer.remaining()]; bytebuffer.get(abyte0);//from ww w. j ava 2s .com return new ByteArrayInputStream(abyte0); }