Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to pass byte[] from one appln to another, which are hosted on different Servers.  RSS feed

 
Shridhar. Blr.
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Can anyone tell me how to transfer/send byte[] from servlet ( C ) another servlet ( B ) , ( and finally to last servlet ( A ) )..
Connection between A, B and C is made thru HttpURLConnection.
I tried this :
To Write Form C 2 B :
ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
byteOutStream.writeTo(response.getOutputStream());
byteOutStream.write(licenseFileBytes);
System.out.print("licenseFile LIA : "+licenseFileBytes);
byteOutStream.close();

Reading the same @ B:
byte[] licenseFile = new byte[500];
ByteArrayInputStream byteInStream = new ByteArrayInputStream (licenseFile);
byteInStream = (ByteArrayInputStream)urlConn.getInputStream();
The above Reading part is throwing Exception , ClassCast Exception ..
and from here i want to write the same byte[] back to A..
Can anyone tell me how to go about doing the same. using any File IO operations..
Any help would be highly appreciated..
Thanks in Advance..
~Shridhar..
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of casting the input stream to a ByteInputStream, instead do the following
BufferedInputStream in = new BufferedInputStream( urlConnection.getInputStream() );
in.read( licenseFile , 0 , 500 );
I'm not sure what type of stream URLConnection returns with getInputStream, but that's the point. You deal with the generic interface and build some other easy to use stream from it, instead of trying to cast it specifically to a certain type.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!