473,385 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

[JAVA] Unbuffered access to stdin

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
Jul 17 '05 #1
5 6110
On Sat, 05 Mar 2005 13:36:22 +0200, Max Rabkin wrote:
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).


AFAIK no.

However if you said why you think you need to do this, maybe someone
could suggest an alternative solution.

/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 #2
Max
Gordon Beaton wrote:
On Sat, 05 Mar 2005 13:36:22 +0200, Max Rabkin wrote:
[unbuffered access to System.in]
However if you said why you think you need to do this, maybe someone
could suggest an alternative solution.


I am writing an interpreter for an esoteric language (in the vein of
BrainF***). The only input instruction is read-byte-to-stack.
/gordon

Jul 17 '05 #3
On Sat, 05 Mar 2005 21:05:44 +0200, Max wrote:
I am writing an interpreter for an esoteric language (in the vein of
BrainF***). The only input instruction is read-byte-to-stack.


I'll interpret that to mean that you want to be able to read from
System.in without waiting for the user to press enter - is that right?
If so, it's your OS console, not Java's buffering of System.in that
prevents it, and consequently unbuffering System.in (alone) won't let
you do it.

You *can* read individual bytes from System.in without waiting for
enter. Try piping input from a file or other source to see that it's
possible.

On unix-like platforms, you can use "stty -icanon min 1" to change
console mode so you can do character-at-a-time input. On other
operating systems, I have no idea.

/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 #4
Max
Gordon Beaton wrote:
You *can* read individual bytes from System.in without waiting for
enter. Try piping input from a file or other source to see that it's
possible.

How? With System.in.read()? Ok. Since that didn't work, I thought it was
Java's fault.
On unix-like platforms, you can use "stty -icanon min 1" to change
console mode so you can do character-at-a-time input. On other
operating systems, I have no idea.
Thanks. I'm currently not running a unix-like platform. Other users of
my computer complain too much if they don't have windows, and last time
a tried a dual-boot setup, my windows died. :(
/gordon

Jul 17 '05 #5

Don't use standard input, then. Build a simple gui where you receive
key down events directly. Then you can do anything you want.

Jul 17 '05 #6

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

Similar topics

5
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...
1
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
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...
4
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...
3
by: yoyojava | last post by:
here go to this link: http://staff.beaumont.k12.tx.us/jchauvi/CS2/CS2.html ..... then click on PROJECT:Bruin Grocery ... and i am done with everything except for step 5 and 6 the search methods.. i...
8
by: yolazyguy | last post by:
Hello I am new but I have been in a intro programming class with Java as the main entree. I have this program where I need to end input characters at 65 characters and break the line and then add a...
7
by: Markus Mayer | last post by:
Hi folks. I'm somewhat new to *nix programming and just ran into a problem. I have to take user input from the terminal but like to constrain that to some rules given, i.e. "numbers only" or...
0
by: Hamish Allan | last post by:
Hi, The man page for python says: "-u Force stdin, stdout and stderr to be totally unbuffered." However, when I try: $ ssh localhost python -u print 'hello, world'
318
by: King Raz | last post by:
The shootout site has benchmarks comparing different languages. It includes C# Mono vs Java but not C# .NET vs Java. So I went through all the benchmark on the site ... ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.