Tabnine Logo
System.setIn
Code IndexAdd Tabnine to your IDE (free)

How to use
setIn
method
in
java.lang.System

Best Java code snippets using java.lang.System.setIn (Showing top 20 results out of 684)

origin: fengjiachun/Jupiter

public static void setIn(InputStream in) {
  System.setIn(in);
}
origin: fengjiachun/Jupiter

public static void setIn(InputStream in) {
  System.setIn(in);
}
origin: stackoverflow.com

 ByteArrayInputStream in = new ByteArrayInputStream("My string".getBytes());
System.setIn(in);

// do your thing

// optionally, reset System.in to its original
System.setIn(System.in)
origin: stackoverflow.com

 String data = "Hello, World!\r\n";
InputStream stdin = System.in;
try {
 System.setIn(new ByteArrayInputStream(data.getBytes()));
 Scanner scanner = new Scanner(System.in);
 System.out.println(scanner.nextLine());
} finally {
 System.setIn(stdin);
}
origin: stanfordnlp/CoreNLP

 /**
  */
 public static void main(String[] args) {
  LatticeXMLReader reader = new LatticeXMLReader();
  try {
   System.setIn(new FileInputStream(args[0]));
  } catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

  reader.load(System.in);

  int numLattices = 0;
  for(Lattice lattice : reader) {
   System.out.println(lattice.toString());
   numLattices++;
  }
  System.out.printf("\nLoaded %d lattices\n", numLattices);
 }
}
origin: stackoverflow.com

 public static void main(String[] args) throws IOException {

  // 1. create the pipes
  PipedInputStream inPipe = new PipedInputStream();
  PipedInputStream outPipe = new PipedInputStream();

  // 2. set the System.in and System.out streams
  System.setIn(inPipe);
  System.setOut(new PrintStream(new PipedOutputStream(outPipe), true));

  PrintWriter inWriter = new PrintWriter(new PipedOutputStream(inPipe), true);

  // 3. create the gui 
  JFrame frame = new JFrame("\"Console\"");
  frame.add(console(outPipe, inWriter));
  frame.setSize(400, 300);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setVisible(true);

  // 4. write some output (to JTextArea)
  System.out.println("Hello World!");
  System.out.println("Test");
  System.out.println("Test");
  System.out.println("Test");

  // 5. get some input (from JTextArea)
  Scanner s = new Scanner(System.in);
  System.out.printf("got from input: \"%s\"%n", s.nextLine());
}
origin: apache/flink

protected static void resetStreamsAndSendOutput() {
  System.setOut(ORIGINAL_STDOUT);
  System.setErr(ORIGINAL_STDERR);
  System.setIn(ORIGINAL_STDIN);
  LOG.info("Sending stdout content through logger: \n\n{}\n\n", outContent.toString());
  LOG.info("Sending stderr content through logger: \n\n{}\n\n", errContent.toString());
}
origin: jphp-group/jphp

@Signature
public static void setIn(Environment env, @Arg(typeClass = "php\\io\\Stream", nullable = true) Memory stream) {
  if (stream.isNull()) {
    System.setIn(null);
  } else {
    System.setIn(Stream.getInputStream(env, stream));
  }
}
origin: spring-projects/spring-batch

@After
public void tearDown() throws Exception {
  System.setIn(stdin);
  StubJobLauncher.tearDown();
}
origin: spring-projects/spring-batch

@Before
public void setUp() throws Exception {
  JobExecution jobExecution = new JobExecution(null, new Long(1), null, null);
  ExitStatus exitStatus = ExitStatus.COMPLETED;
  jobExecution.setExitStatus(exitStatus);
  StubJobLauncher.jobExecution = jobExecution;
  stdin = System.in;
  System.setIn(new InputStream() {
    @Override
    public int read() {
      return -1;
    }
  });
}
origin: remkop/picocli

@Test
public void testInteractiveOptionReadsFromStdInMultiLinePrompt() {
  class App {
    @Option(names = "-x", description = {"Pwd%nline2", "ignored"}, interactive = true) int x;
    @Option(names = "-z") int z;
  }
  PrintStream out = System.out;
  InputStream in = System.in;
  try {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    System.setOut(new PrintStream(baos));
    System.setIn(new ByteArrayInputStream("123".getBytes()));
    App app = new App();
    CommandLine cmd = new CommandLine(app);
    cmd.parse("-x", "-z", "987");
    String expectedPrompt = format("Enter value for -x (Pwd%nline2): ");
    assertEquals(expectedPrompt, baos.toString());
    assertEquals(123, app.x);
    assertEquals(987, app.z);
  } finally {
    System.setOut(out);
    System.setIn(in);
  }
}
origin: remkop/picocli

@Test
public void testInteractivePositionalReadsFromStdIn() {
  class App {
    @Parameters(index = "0", description = {"Pwd%nline2", "ignored"}, interactive = true) int x;
    @Parameters(index = "1") int z;
  }
  PrintStream out = System.out;
  InputStream in = System.in;
  try {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    System.setOut(new PrintStream(baos));
    System.setIn(new ByteArrayInputStream("123".getBytes()));
    App app = new App();
    CommandLine cmd = new CommandLine(app);
    cmd.parse("987");
    String expectedPrompt = format("Enter value for position 0 (Pwd%nline2): ");
    assertEquals(expectedPrompt, baos.toString());
    assertEquals(123, app.x);
    assertEquals(987, app.z);
  } finally {
    System.setOut(out);
    System.setIn(in);
  }
}
origin: apache/flink

System.setIn(in);
origin: remkop/picocli

@Test
public void testInteractivePositional2ReadsFromStdIn() {
  class App {
    @Parameters(index = "0") int a;
    @Parameters(index = "1", description = {"Pwd%nline2", "ignored"}, interactive = true) int x;
    @Parameters(index = "2") int z;
  }
  PrintStream out = System.out;
  InputStream in = System.in;
  try {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    System.setOut(new PrintStream(baos));
    System.setIn(new ByteArrayInputStream("123".getBytes()));
    App app = new App();
    CommandLine cmd = new CommandLine(app);
    cmd.parse("333", "987");
    String expectedPrompt = format("Enter value for position 1 (Pwd%nline2): ");
    assertEquals(expectedPrompt, baos.toString());
    assertEquals(333, app.a);
    assertEquals(123, app.x);
    assertEquals(987, app.z);
  } finally {
    System.setOut(out);
    System.setIn(in);
  }
}
origin: apache/flink

System.setOut(new PrintStream(outContent));
System.setErr(new PrintStream(errContent));
System.setIn(in);
origin: remkop/picocli

@Test
public void testInteractiveOptionReadsFromStdIn() {
  class App {
    @Option(names = "-x", description = {"Pwd", "line2"}, interactive = true) int x;
    @Option(names = "-z") int z;
  }
  PrintStream out = System.out;
  InputStream in = System.in;
  try {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    System.setOut(new PrintStream(baos));
    System.setIn(new ByteArrayInputStream("123".getBytes()));
    App app = new App();
    CommandLine cmd = new CommandLine(app);
    cmd.parse("-x");
    assertEquals("Enter value for -x (Pwd): ", baos.toString());
    assertEquals(123, app.x);
    assertEquals(0, app.z);
    cmd.parse("-z", "678");
    assertEquals(0, app.x);
    assertEquals(678, app.z);
  } finally {
    System.setOut(out);
    System.setIn(in);
  }
}
origin: spring-projects/spring-batch

@Test
public void testWithStdinCommandLine() throws Throwable {
  System.setIn(new InputStream() {
    char[] input = (jobPath+"\n"+jobName+"\nfoo=bar\nspam=bucket").toCharArray();
    int index = 0;
    @Override
    public int available() {
      return input.length - index;
    }
    @Override
    public int read() {
      return index<input.length-1 ? (int) input[index++] : -1;
    }
  });
  CommandLineJobRunner.main(new String[0]);
  assertEquals(0, StubSystemExiter.status);
  assertEquals(2, StubJobLauncher.jobParameters.getParameters().size());
}
  
origin: spring-projects/spring-batch

@Test
public void testWithStdinCommandLineWithEmptyLines() throws Throwable {
  System.setIn(new InputStream() {
    char[] input = (jobPath+"\n"+jobName+"\nfoo=bar\n\nspam=bucket\n\n").toCharArray();
    int index = 0;
    @Override
    public int available() {
      return input.length - index;
    }
    @Override
    public int read() {
      return index<input.length-1 ? (int) input[index++] : -1;
    }
  });
  CommandLineJobRunner.main(new String[0]);
  assertEquals(0, StubSystemExiter.status);
  assertEquals(2, StubJobLauncher.jobParameters.getParameters().size());
}
origin: spring-projects/spring-batch

@Test
public void testWithStdinParameters() throws Throwable {
  String[] args = new String[] { jobPath, jobName };
  System.setIn(new InputStream() {
    char[] input = ("foo=bar\nspam=bucket").toCharArray();
    int index = 0;
    @Override
    public int available() {
      return input.length - index;
    }
    @Override
    public int read() {
      return index<input.length-1 ? (int) input[index++] : -1;
    }
  });
  CommandLineJobRunner.main(args);
  assertEquals(0, StubSystemExiter.status);
  assertEquals(2, StubJobLauncher.jobParameters.getParameters().size());
}
origin: spring-projects/spring-batch

@Test
public void testWithInvalidStdin() throws Throwable {
  System.setIn(new InputStream() {
    @Override
    public int available() throws IOException {
      throw new IOException("Planned");
    }
    @Override
    public int read() {
      return -1;
    }
  });
  CommandLineJobRunner.main(new String[] { jobPath, jobName });
  assertEquals(0, StubSystemExiter.status);
  assertEquals(0, StubJobLauncher.jobParameters.getParameters().size());
}
java.langSystemsetIn

Javadoc

Sets the standard input stream to the given user defined input stream.

Popular methods of System

  • currentTimeMillis
    Returns the current time in milliseconds. Note that while the unit of time of the return value is a
  • getProperty
    Returns the value of a particular system property. The defaultValue will be returned if no such prop
  • arraycopy
  • exit
  • setProperty
    Sets the value of a particular system property.
  • nanoTime
    Returns the current timestamp of the most precise timer available on the local system, in nanosecond
  • getenv
    Returns the value of the environment variable with the given name, or null if no such variable exist
  • getProperties
    Returns the system properties. Note that this is not a copy, so that changes made to the returned Pr
  • identityHashCode
    Returns an integer hash code for the parameter. The hash code returned is the same one that would be
  • getSecurityManager
    Gets the system security interface.
  • gc
    Indicates to the VM that it would be a good time to run the garbage collector. Note that this is a h
  • lineSeparator
    Returns the system's line separator. On Android, this is "\n". The value comes from the value of the
  • gc,
  • lineSeparator,
  • clearProperty,
  • setOut,
  • setErr,
  • console,
  • loadLibrary,
  • load,
  • setSecurityManager,
  • mapLibraryName

Popular in Java

  • Finding current android device location
  • addToBackStack (FragmentTransaction)
  • getSystemService (Context)
  • setContentView (Activity)
  • URLConnection (java.net)
    A connection to a URL for reading or writing. For HTTP connections, see HttpURLConnection for docume
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • JPanel (javax.swing)
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now