473,651 Members | 2,645 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I get unbuffered InputStream from Process?

Hi.

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

I found out that java.lang.Win32 Process and java.lang.UNIXP rocess both
wraps the stdout with java.io.Buffere dInputStream, but I need an
unbuffered one.
Jul 17 '05 #1
5 8530
Seong Jin, Cho wrote:
Hi.

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

I found out that java.lang.Win32 Process and java.lang.UNIXP rocess both
wraps the stdout with java.io.Buffere dInputStream, 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.
Jul 17 '05 #2
On 17 Jun 2004 01:01:29 -0700, Seong Jin, Cho wrote:
Is there a way to get an unbuffered InputStream from Process?

I found out that java.lang.Win32 Process and java.lang.UNIXP rocess
both wraps the stdout with java.io.Buffere dInputStream, 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 "immediatel y", 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,N ULL);

/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
Jul 17 '05 #3
Hello gordon.
What makes you think it's buffered, and perhaps more importantly, why
From Win32Process.ja va:

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.A ccessController .doPrivileged(
new java.security.P rivilegedAction () {
public Object run() {
stdin_stream =
new BufferedOutputS tream(new FileOutputStrea m(stdin_fd));
stdout_stream =
new BufferedInputSt ream(new FileInputStream (stdout_fd));
stderr_stream =
new FileInputStream (stderr_fd);
return null;
}
});

Also, from solaris version of UNIXProcess.jav a:

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

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

java.security.A ccessController .doPrivileged(
new java.security.P rivilegedAction () {
public Object run() {
stdin_stream
= new BufferedOutputS tream(new FileOutputStrea m(stdin_fd));
stdout_inner_st ream = new DeferredCloseIn putStream(stdou t_fd);
stdout_stream = new BufferedInputSt ream(stdout_inn er_stream);
stderr_stream = new DeferredCloseIn putStream(stder r_fd);
return null;
}
});

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 "immediatel y", 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,N ULL);

/gordon
Actually, I'm doing the buffering myself, and I don't want to do the
buffering doubly. (I know BufferedInputSt ream is highly optimized
implementation, but I want to access the underlying byte-array
buffer.)
If your observation is that the output of the child process does not
reach the Java parent "immediatel y", then the buffering is occuring in
the child process itself, not in Java.


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

- Seong Jin
Jul 17 '05 #4
On 17 Jun 2004 18:46:52 -0700, Seong Jin, Cho wrote:
Does the output reach the java parent "immediatel y" even if
BufferedInputSt ream 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
BufferedInputSt ream it is available to the holder of the
BufferedInputSt ream.

The situation is different if the buffering occurs in the sending
process, i.e. data isn't sent until enough has been buffered.
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
Jul 17 '05 #5
i20
Hi!

have you found a solution in order to obtain a simple InputStream fro
the Process.getInpu tStream()?

In fact, I've got the same problem with the BufferedInputSt ream whic
is return by the Process.getInpu tStream() method.

The main problem is to obtain the InputStream on which thi
BufferedInputSt ream is based on. Indeed, this InputStream is in fact
FileInputStream (like the Stream returned by Process.getErro rStream)..
and on a FileInputStream , since it's possible to get a Channel, you wil
be able to deal with NIO stream (java 1.4), in order to obtai
non-blockant threads, which could be easily stopped.

I haven't find any solution yet... and don't see how it will b
possible with the current stable version of Java (1.4.2)

i2
-
i2
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
6139
by: Max Rabkin | last post by:
While java's System.in is, according to the javadocs, an InputStream, it is in fact an instance of java.io.BufferedInputStream. Is there any way to have unbuffered access to it without hacking the JRE? (I can do it on my own computer, simply changing FilterInputStream's "in" field from "protected" to "public", but then I can't distribute my program). --Max
5
5150
by: Rich | last post by:
Does anyone know the correct way of opening an unbuffered output file using STL? I attempted: ofstream myfile("fname.txt", ios::binary); myfile.setbuf(NULL, 0); and I was informed that setbuf is not a member of
1
2877
by: | last post by:
Is this even possible? I've found some references to specific "unbuffered" type methods that exist in older incarnations of basic_streambuf but not in newer ones. Info please. :P
11
3242
by: Lonnie Princehouse | last post by:
>From the cmd shell on both Windows 2k and XP, I'm getting this weird syntax error in conjunction with the unbuffered flag. It works fine without -u. Has anyone else encountered it? This didn't happen with Python 2.2... C:\>python -u Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print 'hello'
4
4177
by: pank7 | last post by:
hi everyone, I have a program here to test the file IO(actually output) with buffer turned on and off. What I want to see is that there will be obvious differece in time. Here I have an input file scales 1.1M, what I did is just copy it to another output file(ten times). But I don't think I see any difference. My file system is ext3, with debian sarge(kernel-2.6.8). Here is the main part of my program:
1
8100
by: samtilden | last post by:
I want to print out some tracing messages from Global.asax.cs/Application_BeginRequest(). I easily got: System.Web.HttpContext.Current.Request.RawUrl, and System.Web.HttpContext.Current.Request.Params. I would now like to get the entire:
4
1746
by: max | last post by:
hey folks, coming from java, new to python. i'm trying to port a java app to python that writes an inputstream to a buffer, then parses the buffer (specifically, i'm getting ID3 tags from mp3s online). i understand that this java approach to the task may not apply to python, but i'm having trouble finding a working approach in python. i currently have locations of the mp3s in question as strings, which works for parsing local files,...
1
4632
by: Yang Zhang | last post by:
Hi, is there any way to get unbuffered stdout/stderr without relying on the -u flag to python or calling .flush() on each print (including indirect hacks like replacing sys.stdout with a wrapper that succeeds each write() with a flush())? Thanks in advance! -- Yang Zhang http://www.mit.edu/~y_z/
8
14730
by: zeeshan708 | last post by:
what is the difference between the buffered and unbuffered stream ??(e.g we say that cout is buffered and cerr is unbuffered stream) does that mean that the output sent to buffered stream have to go through a buffer (i.e a temporary storage registers) ,, if so then what is the big deal in unbuffered stream??
0
8792
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8694
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8457
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8571
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7294
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5605
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1905
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.