473,624 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[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.Buffere dInputStream. Is there any way
to have unbuffered access to it without hacking the JRE? (I can do it on
my own computer, simply changing FilterInputStre am's "in" field from
"protected" to "public", but then I can't distribute my program).

--Max
Jul 17 '05 #1
5 6136
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.Buffere dInputStream. Is there any way
to have unbuffered access to it without hacking the JRE? (I can do it on
my own computer, simply changing FilterInputStre am'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
5149
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
2876
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
4176
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:
3
2050
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 have posted my code so you can helpme with my search methods :D. DONT HELP ME WITH STEP 3 & 4 because I can already do those. JUST STEP 5 & 6 which is the serch methods is where I need help. Thanks a bunch.. only a real java genius should be able to...
8
2434
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 new line. This is my code: import static java.lang.System.*; import java.util.Scanner; class formatter3 { public static void main (String args) {
7
6150
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 "alphanumeric only" etc. scanf would do, but I don't like the fact that wrong ('disallowed') characters are visible and all that stuff. For that I need unbuffered input. Since there seems to be no atomic function to do that I tried to fiddle around...
0
1204
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
10945
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 ... http://kingrazi.blogspot.com/2008/05/shootout-c-net-vs-java-benchmarks.html Just to keep the post on topic for my friends at comp.lang.c++, how do I play default windows sounds with C++?
0
8179
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8685
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
8633
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
8348
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
8493
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
7176
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...
0
5570
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
4084
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...
0
4187
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.