Java Code Examples for java.io.FileDescriptor#in()

The following examples show how to use java.io.FileDescriptor#in() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileTest6.java    From mini-jvm with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {

    try (FileInputStream fis = new FileInputStream(FileDescriptor.in)) {
      while (true) {
        int read = fis.read();
        System.out.println(read);
      }
    }
  }
 
Example 2
Source File: WindowsTerminal.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected boolean isSystemIn(final InputStream in) throws IOException {
    if (in == null) {
        return false;
    }
    else if (in == System.in) {
        return true;
    }
    else if (in instanceof FileInputStream && ((FileInputStream) in).getFD() == FileDescriptor.in) {
        return true;
    }

    return false;
}
 
Example 3
Source File: WindowsTerminal.java    From TorrentEngine with GNU General Public License v3.0 5 votes vote down vote up
protected boolean isSystemIn(final InputStream in) throws IOException {
    if (in == null) {
        return false;
    }
    else if (in == System.in) {
        return true;
    }
    else if (in instanceof FileInputStream && ((FileInputStream) in).getFD() == FileDescriptor.in) {
        return true;
    }

    return false;
}
 
Example 4
Source File: ConsoleService.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void run() {
	try(
		FileInputStream fis = new FileInputStream( FileDescriptor.in );
		BufferedReader stdin = new BufferedReader(
			new InputStreamReader(
				Channels.newInputStream(
					fis.getChannel() ) ) ) ) {
		String line;
		while( keepRun ) {
			line = stdin.readLine();

			if( sessionListeners ) {

				for( String s : sessionTokens.keySet() ) {
					Value v = Value.create();
					v.getFirstChild( "token" ).setValue( s );
					v.setValue( line );
					sendMessage( CommMessage.createRequest( "in", "/", v ) );
				}
			} else {
				sendMessage( CommMessage.createRequest( "in", "/", Value.create( line ) ) );
			}
		}
	} catch( ClosedByInterruptException ce ) {
	} catch( IOException e ) {
		interpreter().logWarning( e );
	}
}
 
Example 5
Source File: HeroicShell.java    From heroic with Apache License 2.0 5 votes vote down vote up
static void runInteractiveShell(final CoreInterface core) throws Exception {
    final List<CommandDefinition> commands = new ArrayList<>(core.commands());

    commands.add(CommandDefinition.newBuilder()
        .setName("clear")
        .setUsage("Clear the current shell")
        .build());
    commands.add(CommandDefinition.newBuilder()
        .setName("timeout")
        .setUsage("Get or set the current task timeout")
        .build());
    commands.add(CommandDefinition.newBuilder()
        .setName("exit")
        .setUsage("Exit the shell")
        .build());

    try (final FileInputStream input = new FileInputStream(FileDescriptor.in)) {
        final HeroicInteractiveShell interactive =
            HeroicInteractiveShell.buildInstance(commands, input);

        try {
            interactive.run(core);
        } finally {
            interactive.shutdown();
        }
    }
}
 
Example 6
Source File: JLineConsole.java    From es6draft with MIT License 5 votes vote down vote up
private static ConsoleReader newConsoleReader(String programName) throws IOException {
    final boolean isWindows = isWindows();
    final String type = System.getProperty(TerminalFactory.JLINE_TERMINAL);
    if (isWindows && type == null) {
        TerminalFactory.registerFlavor(TerminalFactory.Flavor.WINDOWS, UnsupportedTerminal.class);
    } else if (isWindows && type.equalsIgnoreCase(TerminalFactory.UNIX)) {
        TerminalFactory.registerFlavor(TerminalFactory.Flavor.UNIX, CygwinTerminal.class);
    }
    FileInputStream in = new FileInputStream(FileDescriptor.in);
    Terminal terminal = TerminalFactory.get();
    ConsoleReader consoleReader = new ConsoleReader(programName, in, System.out, terminal, getDefaultEncoding());
    consoleReader.setExpandEvents(false);
    return consoleReader;
}
 
Example 7
Source File: System.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize the system class.  Called after thread initialization.
 */
private static void initPhase1() {
    // VM might invoke JNU_NewStringPlatform() to set those encoding
    // sensitive properties (user.home, user.name, boot.class.path, etc.)
    // during "props" initialization.
    // The charset is initialized in System.c and does not depend on the Properties.
    Map<String, String> tempProps = SystemProps.initProperties();
    VersionProps.init(tempProps);

    // There are certain system configurations that may be controlled by
    // VM options such as the maximum amount of direct memory and
    // Integer cache size used to support the object identity semantics
    // of autoboxing.  Typically, the library will obtain these values
    // from the properties set by the VM.  If the properties are for
    // internal implementation use only, these properties should be
    // masked from the system properties.
    //
    // Save a private copy of the system properties object that
    // can only be accessed by the internal implementation.
    VM.saveProperties(tempProps);
    props = createProperties(tempProps);

    StaticProperty.javaHome();          // Load StaticProperty to cache the property values

    lineSeparator = props.getProperty("line.separator");

    FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
    FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
    FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
    setIn0(new BufferedInputStream(fdIn));
    setOut0(newPrintStream(fdOut, props.getProperty("sun.stdout.encoding")));
    setErr0(newPrintStream(fdErr, props.getProperty("sun.stderr.encoding")));

    // Setup Java signal handlers for HUP, TERM, and INT (where available).
    Terminator.setup();

    // Initialize any miscellaneous operating system settings that need to be
    // set for the class libraries. Currently this is no-op everywhere except
    // for Windows where the process-wide error mode is set before the java.io
    // classes are used.
    VM.initializeOSEnvironment();

    // The main thread is not added to its thread group in the same
    // way as other threads; we must do it ourselves here.
    Thread current = Thread.currentThread();
    current.getThreadGroup().add(current);

    // register shared secrets
    setJavaLangAccess();

    ClassLoader.initLibraryPaths();

    // Subsystems that are invoked during initialization can invoke
    // VM.isBooted() in order to avoid doing things that should
    // wait until the VM is fully initialized. The initialization level
    // is incremented from 0 to 1 here to indicate the first phase of
    // initialization has completed.
    // IMPORTANT: Ensure that this remains the last initialization action!
    VM.initLevel(1);
}
 
Example 8
Source File: System.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initialize the system class.  Called after thread initialization.
 */
private static void initPhase1() {

    // VM might invoke JNU_NewStringPlatform() to set those encoding
    // sensitive properties (user.home, user.name, boot.class.path, etc.)
    // during "props" initialization, in which it may need access, via
    // System.getProperty(), to the related system encoding property that
    // have been initialized (put into "props") at early stage of the
    // initialization. So make sure the "props" is available at the
    // very beginning of the initialization and all system properties to
    // be put into it directly.
    props = new Properties();
    initProperties(props);  // initialized by the VM

    // There are certain system configurations that may be controlled by
    // VM options such as the maximum amount of direct memory and
    // Integer cache size used to support the object identity semantics
    // of autoboxing.  Typically, the library will obtain these values
    // from the properties set by the VM.  If the properties are for
    // internal implementation use only, these properties should be
    // removed from the system properties.
    //
    // See java.lang.Integer.IntegerCache and the
    // VM.saveAndRemoveProperties method for example.
    //
    // Save a private copy of the system properties object that
    // can only be accessed by the internal implementation.  Remove
    // certain system properties that are not intended for public access.
    VM.saveAndRemoveProperties(props);

    lineSeparator = props.getProperty("line.separator");
    VersionProps.init();

    FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
    FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
    FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
    setIn0(new BufferedInputStream(fdIn));
    setOut0(newPrintStream(fdOut, props.getProperty("sun.stdout.encoding")));
    setErr0(newPrintStream(fdErr, props.getProperty("sun.stderr.encoding")));

    // Load the zip library now in order to keep java.util.zip.ZipFile
    // from trying to use itself to load this library later.
    loadLibrary("zip");

    // Setup Java signal handlers for HUP, TERM, and INT (where available).
    Terminator.setup();

    // Initialize any miscellaneous operating system settings that need to be
    // set for the class libraries. Currently this is no-op everywhere except
    // for Windows where the process-wide error mode is set before the java.io
    // classes are used.
    VM.initializeOSEnvironment();

    // The main thread is not added to its thread group in the same
    // way as other threads; we must do it ourselves here.
    Thread current = Thread.currentThread();
    current.getThreadGroup().add(current);

    // register shared secrets
    setJavaLangAccess();

    // Subsystems that are invoked during initialization can invoke
    // VM.isBooted() in order to avoid doing things that should
    // wait until the VM is fully initialized. The initialization level
    // is incremented from 0 to 1 here to indicate the first phase of
    // initialization has completed.
    // IMPORTANT: Ensure that this remains the last initialization action!
    VM.initLevel(1);
}
 
Example 9
Source File: CygwinPty.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public InputStream getSlaveInput() throws IOException {
    return new FileInputStream(FileDescriptor.in);
}
 
Example 10
Source File: ECMA48Terminal.java    From jexer with MIT License 4 votes vote down vote up
/**
 * Constructor sets up state for getEvent().
 *
 * @param listener the object this backend needs to wake up when new
 * input comes in
 * @param input an InputStream connected to the remote user, or null for
 * System.in.  If System.in is used, then on non-Windows systems it will
 * be put in raw mode; shutdown() will (blindly!) put System.in in cooked
 * mode.  input is always converted to a Reader with UTF-8 encoding.
 * @param output an OutputStream connected to the remote user, or null
 * for System.out.  output is always converted to a Writer with UTF-8
 * encoding.
 * @throws UnsupportedEncodingException if an exception is thrown when
 * creating the InputStreamReader
 */
public ECMA48Terminal(final Object listener, final InputStream input,
    final OutputStream output) throws UnsupportedEncodingException {

    resetParser();
    mouse1           = false;
    mouse2           = false;
    mouse3           = false;
    stopReaderThread = false;
    this.listener    = listener;

    if (input == null) {
        // inputStream = System.in;
        inputStream = new FileInputStream(FileDescriptor.in);
        sttyRaw();
        setRawMode = true;
    } else {
        inputStream = input;
    }
    this.input = new InputStreamReader(inputStream, "UTF-8");

    if (input instanceof SessionInfo) {
        // This is a TelnetInputStream that exposes window size and
        // environment variables from the telnet layer.
        sessionInfo = (SessionInfo) input;
    }
    if (sessionInfo == null) {
        if (input == null) {
            // Reading right off the tty
            sessionInfo = new TTYSessionInfo();
        } else {
            sessionInfo = new TSessionInfo();
        }
    }

    if (output == null) {
        this.output = new PrintWriter(new OutputStreamWriter(System.out,
                "UTF-8"));
    } else {
        this.output = new PrintWriter(new OutputStreamWriter(output,
                "UTF-8"));
    }

    // Enable mouse reporting and metaSendsEscape
    this.output.printf("%s%s", mouse(true), xtermMetaSendsEscape(true));
    this.output.flush();

    // Query the screen size
    sessionInfo.queryWindowSize();
    setDimensions(sessionInfo.getWindowWidth(),
        sessionInfo.getWindowHeight());

    // Hang onto the window size
    windowResize = new TResizeEvent(TResizeEvent.Type.SCREEN,
        sessionInfo.getWindowWidth(), sessionInfo.getWindowHeight());

    // Permit RGB colors only if externally requested
    if (System.getProperty("jexer.ECMA48.rgbColor") != null) {
        if (System.getProperty("jexer.ECMA48.rgbColor").equals("true")) {
            doRgbColor = true;
        } else {
            doRgbColor = false;
        }
    }

    // Spin up the input reader
    eventQueue = new LinkedList<TInputEvent>();
    readerThread = new Thread(this);
    readerThread.start();

    // Clear the screen
    this.output.write(clearAll());
    this.output.flush();
}
 
Example 11
Source File: ConsoleReader.java    From openjdk-jdk9 with GNU General Public License v2.0 votes vote down vote up
public ConsoleReader() throws IOException {
    this(null, new FileInputStream(FileDescriptor.in), System.out, null);
}