AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How can I get unbuffered InputStream from Process?

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> comp.lang.java.api
View previous topic :: View next topic  
Author Message
Seong Jin, Cho
Guest





PostPosted: Thu Jun 17, 2004 8:01 am    Post subject: How can I get unbuffered InputStream from Process? Reply with quote



Hi.

Is there a way to get an unbuffered InputStream from Process?

I found out that java.lang.Win32Process and java.lang.UNIXProcess both
wraps the stdout with java.io.BufferedInputStream, but I need an
unbuffered one.
Back to top
Raymond DeCampo
Guest





PostPosted: Thu Jun 17, 2004 11:40 am    Post subject: Re: How can I get unbuffered InputStream from Process? Reply with quote



Seong Jin, Cho wrote:
Quote:
Hi.

Is there a way to get an unbuffered InputStream from Process?

I found out that java.lang.Win32Process and java.lang.UNIXProcess both
wraps the stdout with java.io.BufferedInputStream, but I need an
unbuffered one.

Sounds like you need to use JNI then and use native code.

--
XML is the programmer's duct tape.

Back to top
Gordon Beaton
Guest





PostPosted: Thu Jun 17, 2004 4:30 pm    Post subject: Re: How can I get unbuffered InputStream from Process? Reply with quote



On 17 Jun 2004 01:01:29 -0700, Seong Jin, Cho wrote:
Quote:
Is there a way to get an unbuffered InputStream from Process?

I found out that java.lang.Win32Process and java.lang.UNIXProcess
both wraps the stdout with java.io.BufferedInputStream, but I need
an unbuffered one.

What makes you think it's buffered, and perhaps more importantly, why
should it make any difference to your java application? What actual
problem do you need to solve?

If your observation is that the output of the child process does not
reach the Java parent "immediately", then the buffering is occuring in
the child process itself, not in Java.

If that's the case, you can prevent that from happening by doing this
near the start of the child process, i.e. before writing anything to
stdout:

setvbuf(stdout,NULL,_IONBUF,0);
or
setbuf(stdout,NULL);

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e

Back to top
Seong Jin, Cho
Guest





PostPosted: Fri Jun 18, 2004 1:46 am    Post subject: Re: How can I get unbuffered InputStream from Process? Reply with quote

Hello gordon.

Quote:
What makes you think it's buffered, and perhaps more importantly, why

From Win32Process.java:

stdin_fd = new FileDescriptor();
stdout_fd = new FileDescriptor();
stderr_fd = new FileDescriptor();

handle = create(cmdstr, envstr, path, stdin_fd, stdout_fd, stderr_fd);
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
stdin_stream =
new BufferedOutputStream(new FileOutputStream(stdin_fd));
stdout_stream =
new BufferedInputStream(new FileInputStream(stdout_fd));
stderr_stream =
new FileInputStream(stderr_fd);
return null;
}
});

Also, from solaris version of UNIXProcess.java:

stdin_fd = new FileDescriptor();
stdout_fd = new FileDescriptor();
stderr_fd = new FileDescriptor();

pid = forkAndExec(cmdarray, env, path, stdin_fd, stdout_fd,
stderr_fd);

java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
stdin_stream
= new BufferedOutputStream(new FileOutputStream(stdin_fd));
stdout_inner_stream = new DeferredCloseInputStream(stdout_fd);
stdout_stream = new BufferedInputStream(stdout_inner_stream);
stderr_stream = new DeferredCloseInputStream(stderr_fd);
return null;
}
});


Quote:
should it make any difference to your java application? What actual
problem do you need to solve?

If your observation is that the output of the child process does not
reach the Java parent "immediately", then the buffering is occuring in
the child process itself, not in Java.

If that's the case, you can prevent that from happening by doing this
near the start of the child process, i.e. before writing anything to
stdout:

setvbuf(stdout,NULL,_IONBUF,0);
or
setbuf(stdout,NULL);

/gordon

Actually, I'm doing the buffering myself, and I don't want to do the
buffering doubly. (I know BufferedInputStream is highly optimized
implementation, but I want to access the underlying byte-array
buffer.)

Quote:
If your observation is that the output of the child process does not
reach the Java parent "immediately", then the buffering is occuring in
the child process itself, not in Java.

Does the output reach the java parent "immediately" even if
BufferedInputStream wraps the output? If it's the case, why
UNIXProcess and Win32Process not wrap the stderr also?

- Seong Jin

Back to top
Gordon Beaton
Guest





PostPosted: Fri Jun 18, 2004 5:29 am    Post subject: Re: How can I get unbuffered InputStream from Process? Reply with quote

On 17 Jun 2004 18:46:52 -0700, Seong Jin, Cho wrote:
Quote:
Does the output reach the java parent "immediately" even if
BufferedInputStream wraps the output?

I don't see why a buffer in the receiving process should delay the
reception of data. Once the data has arrived at the
BufferedInputStream it is available to the holder of the
BufferedInputStream.

The situation is different if the buffering occurs in the sending
process, i.e. data isn't sent until enough has been buffered.

Quote:
If it's the case, why UNIXProcess and Win32Process not wrap the
stderr also?

You'll have to ask Sun about that!

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> comp.lang.java.api All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.