⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testpipes.java

📁 java2 primer plus一书源程序
💻 JAVA
字号:
/* * TestPipes.java * * Created on September 27, 2002, 11:29 AM */package ch18;import java.io.*;/** * * @author  Stephen Potts */public class TestPipes{        /** Creates a new instance of TestPipes */    public TestPipes()    {    }        public static void writeData(OutputStream os)    {        try        {            DataOutputStream out = new DataOutputStream(            new BufferedOutputStream(os));                        int[] numArray =            { 1, 10, 2, 9, 3, 7, 4, 6, 5, 100, 200 };                        for(int i=0; i<numArray.length; i++)            {                out.writeInt(numArray[i]);            }                        out.flush();            out.close();        }catch (IOException ioe)        {            ioe.printStackTrace();        }    }        public static void readData(InputStream is)    {        try        {            DataInputStream in = new DataInputStream(            new BufferedInputStream(is));            boolean eof = false;                        while(!eof)            {                try                {                    int iValue = in.readInt();                    System.out.println("read value = " + iValue);                }catch(EOFException eofe)                {                    eof = true;                }            }            System.out.println("End of Data");        }catch (IOException ioe)        {            ioe.printStackTrace();        }    }            public static void main(String[] args)    {        try        {            final PipedOutputStream pos=            new PipedOutputStream();                        final PipedInputStream pis=            new PipedInputStream(pos);                        Runnable runOutput = new Runnable()            {                public void run()                {                    writeData(pos);                }            };                        Thread outThread = new Thread(runOutput, "outThread");            outThread.start();                        Runnable runInput = new Runnable()            {                public void run()                {                    readData(pis);                }            };                        Thread inThread = new Thread(runInput, "inThread");            inThread.start();        }catch (IOException ioe)        {            ioe.printStackTrace();        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -