venkata satya prasad Kolla

Greenhorn
+ Follow
since Oct 24, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by venkata satya prasad Kolla

Hi, I have to convert a ByteArryinputString to a string and then decode the string to ByteArrayInputStream.

here is the code i am using to convert the Byte array input stream to String.

generatedInputStream is of type ByteArrayInputStream:

if(generatedInputStream != null){
byte[] buffer = new byte[generatedInputStream.available()];
int bytesRead;
try {
bytesRead = generatedInputStream.read(buffer);
while (bytesRead >= 0)
{
generatedOutputStream.write(buffer, 0, bytesRead);
bytesRead = generatedInputStream.read(buffer);
}
} catch (IOException e) {
// TODO Auto-generated catch block
throw new SSPApplicationException();
}
}
if(generatedOutputStream.size() > 0){
generatedDoc = new String(generatedOutputStream.toByteArray());
}


String to ByteArrayInputStream:

byte generatedDocBytes[] = generatedDoc.getBytes();
ByteArrayInputStream generatedDocBAIS = new ByteArrayInputStream(generatedDocBytes);

The issue is the two attributes generatedInputStream and generatedDocBAIS are not similar. Their size is not the same. In the transformation i lost some bytes. Can some one suggest me how to convert a ByteArrayInputStream type to String and then convert the String to a ByteArrayInputStream
15 years ago