pipetest.java
来自「JAVA网络编程技术内幕一书的源代码」· Java 代码 · 共 46 行
JAVA
46 行
/* * Java Network Programming, Second Edition * Merlin Hughes, Michael Shoffner, Derek Hamner * Manning Publications Company; ISBN 188477749X * * http://nitric.com/jnp/ * * Copyright (c) 1997-1999 Merlin Hughes, Michael Shoffner, Derek Hamner; * all rights reserved; see license.txt for details. */import java.io.*;
public class PipeTest extends Thread {
protected DataInputStream dataIn;
public PipeTest (InputStream in) {
dataIn = new DataInputStream (in);
}
public void run () {
try {
String line;
while ((line = dataIn.readLine ()) != null)
System.out.println (line.toUpperCase ());
dataIn.close ();
} catch (IOException ex) {
ex.printStackTrace ();
}
}
public static void main (String[] args) throws IOException, InterruptedException {
PipedOutputStream pipedOut = new PipedOutputStream ();
PipedInputStream pipedIn = new PipedInputStream (pipedOut);
PipeTest pipeTest = new PipeTest (pipedIn);
pipeTest.start ();
byte[] buffer = new byte[16];
int numberRead;
while ((numberRead = System.in.read (buffer)) > -1) {
pipedOut.write (buffer, 0, numberRead);
Thread.sleep (1000);
}
pipedOut.close ();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?