Rather than managing your own byte arrays, you could also just have a stack local byte array of some size, read from BufferedInputStream or DataInputStream into your stack local array and write it into a ByteArrayOutputStream.
When you are done you can use ByteArrayOutputStream.toByteArray() to get the full byte array. --- Jim Kellerman, Powerset (Live Search, Microsoft Corporation) > -----Original Message----- > From: Jim Kellerman (POWERSET) [mailto:[email protected]] > Sent: Tuesday, January 13, 2009 8:31 AM > To: [email protected] > Subject: RE: How can I convert from InputStream to Byte[] > > Well, you could wrap InputStream with either BufferedInputStream > (and use BufferedInputStream.read(byte[] b, int off, int len)) > or wrap InputStream with a DataInputStream (and use either > DataInputStream.read(byte[] b) or > DataInputStream.read(byte[] b, int off, int len)) > > In either case above, if the data you were reading were larger > than your byte[] array, you'd have to allocate a bigger one and > use System.arrayCopy to move the data from the old buffer to the > new. > > When you say the InputStream is large, how large is that? > Are you going to store it as a value in an HBase column? > > --- > Jim Kellerman, Powerset (Live Search, Microsoft Corporation) > > > > -----Original Message----- > > From: trongtran asnet [mailto:[email protected]] > > Sent: Tuesday, January 13, 2009 1:31 AM > > To: [email protected] > > Subject: How can I convert from InputStream to Byte[] > > > > Dear all, > > > > The curent, I can convert from InputStream to byte[] by: Convert > > InputStream -> String -> byte[] > > This suluction is not good, because data InputStream is large. Have you > > ever convert it? please help me >
