aspose file tools*
The moose likes I/O and Streams and the fly likes change tream input in process Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "change tream input in process" Watch "change tream input in process" New topic
Author

change tream input in process

John McWon
Greenhorn

Joined: Jan 04, 2001
Posts: 4
Hello,
I have a function define as follow:
ProxyStreamHandler(InputStream from, OutputStream to)
{
LineNumberReader in=null;
BufferedWriter out=null;
BufferedInputStream from=null;
BufferedOutputStream to=null;
String firstLine = null;
byte [] byteInSecondLine = new byte[20];
this.from = new BufferedInputStream(from);
this.to = new BufferedOutputStream(to);
in = new LineNumberReader(new InputStreamReader(from));
out = new BufferedWriter(new OutputStreamWriter(to));
firstLine = in.readLine();
//after I read first line, can I do this?
from.read(bytesInSecondLine);
}
Please show me the correct way.
Thanks
Peter Tran
Bartender

Joined: Jan 02, 2001
Posts: 783
John,
I'm not sure I understand your requirements. I can't believe I'm going to ask this, but can you explain what you're trying to accomplish. Ususally, I would ask for some sample code, but from yours I really can't tell what you're trying to accomplish. I can probaby take a guess, but I'd rather hear it from you. As is, your method will not compile, because the last statement from.read(bytesInSecondLine), the "from" variable hasn't been initialized.
-Peter
John McWon
Greenhorn

Joined: Jan 04, 2001
Posts: 4
Peter,
What I want is that after I connected to a server, when I read through the stream, I need to know what the file type is passing, if it is text/html, I will go ahead use InputStreamReader, if it is .GIF, I change to use InputStream. because InputStreamReader cannot read image file well.
Peter Tran
Bartender

Joined: Jan 02, 2001
Posts: 783
John,
Rather than trying to deduce the file type from the content of the file, can't you just pass that information back first before getting the file?
E.g.

I think this is a better approach rather than trying to deduce the type from the content of the file.
-Peter
Peter Tran
Bartender

Joined: Jan 02, 2001
Posts: 783
BTW - I'm not sure how your example code accomplishes your requirement. It might help if you went back and formatted your example, and add some comments.
Thanks,
-Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: change tream input in process
 
Similar Threads
I/O what is needed for exam?
Problem in WebServer
BufferedInputStream: read() vs read(byte[])
File downloads...
Read, Send, Write a File through a socket