All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.baltoro.client.util.StreamUtil Maven / Gradle / Ivy

There is a newer version: 4.0.12
Show newest version
package io.baltoro.client.util;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.ObjectOutputStream;


public class StreamUtil
{
	

	public static byte[] toBytes(InputStream in) throws Exception
	{
		ByteArrayOutputStream os = new ByteArrayOutputStream();

		byte[] buffer = new byte[1024];
		int len;

		try
		{
			while ((len = in.read(buffer)) != -1) 
			{
				os.write(buffer, 0, len);
			}
		}
		catch(Exception e)
		{
			return null;
		}

		return os.toByteArray();
	}
	
	public static byte[] toBytes(Object obj) throws Exception
	{
		
		ByteArrayOutputStream out = new ByteArrayOutputStream();
	    ObjectOutputStream os = new ObjectOutputStream(out);
	    os.writeObject(obj);
	    return out.toByteArray();
		
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy