Total members 11890 |It is currently Thu Apr 25, 2024 11:53 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





I have method that returns outputstream and I want to pass this to another method that takes inputstream as a parameter
is it possible ?




Author:
Newbie
User avatar Posts: 2
Have thanks: 0 time

Dear Mohamed,
well you cant do that since these are 2 different types of streams, but why dont you post what your code is about and i think it will be more helpful.
Regards


Author:
Newbie
User avatar Posts: 2
Have thanks: 0 time

i have outputstream that write(buffer); and inputstream that read(buffer)
and it is the same buffer means one class write and the other read but they are 2 applications and they uses sockets but i want them one program so i used file to write buffer then i read buffer again from file
but there is a lot of processing is there is any solutions sorry for not write the code it seems to be complicated.


Author:
Newbie
User avatar Posts: 2
Have thanks: 0 time

why don't you make client and server , using sockets ?

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

well you can create a third class -assuming that write is in a class diffrent than read- and create two objects one from write and one from read, and the shared buffer you want to use, and start using the operations u want
e.g.
MyWriter write= new ...;
MyReader read=new ...;
String buffer;
read.read(buffer);
if(buffer!=null)
write.write(buffer);

i hope i understand your problem right and i hope my answer helps you.


Author:
Newbie
User avatar Posts: 2
Have thanks: 0 time

If your data can fits into memory the best way is to first write the data to a ByteArrayOutputStream, then get the byte array and make a new ByteArrayInputStream from the previous byte array.
Code:
ByteArrayOutputStream buffer=new ByteArrayOutputStream();
write(buffer);
InputStream is=new ByteArrayInputStream(buffer.toByteArray());
...

Another possibility is to write your data to a temporary file and read it back.
A third possibility is to use java pipes (PipeInputStream and PipeOutputStream) this last possibility involve to make a new thread and it's quite complicated. I suggest you have a look to http://io-tools.googlecode.com (OutputStreamToInputStream class).


Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time

thanks alot :)

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

Code sample below converts inputstream to outputstream.
Code:

Code:
import java.io.*;
public class InputToOutputStream {
public static void main( String args[] ) throws IOException
{
InputStream in = new FileInputStream ( "InputToOutputStream.java" );
OutputStream out = System.out;
int nextChar;
  while ( ( nextChar = in.read() ) != -1 )
out.write( Character.toUpperCase( (char) nextChar ) );
out.write( '\n' );
out.flush();
} }



Author:
Newbie
User avatar Posts: 5
Have thanks: 0 time
Post new topic Reply to topic  [ 8 posts ] 

  Related Posts  to : Convert outputstream to inputstream
 outputstream to inputstream     -  
 How to Convert WMV to AVI on Mac     -  
 convert timestamp using javascript     -  
 Convert String to Date     -  
 convert pascal code to c ?     -  
 convert hexadecimal to decimal     -  
 convert XMLGregorianCalendar to GregorianCalendar     -  
 convert word, Excel to PDF     -  
 convert lowercase to uppercase     -  



Topic Tags

Java Files and I/O
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com