Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

change tream input in process

 
John McWon
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic