OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [test/] [java.io/] [PipedStreamTest.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/*************************************************************************
2
/* PipedStreamTest.java -- Tests Piped{Input,Output}Stream's
3
/*
4
/* Copyright (c) 1998 Free Software Foundation, Inc.
5
/* Written by Aaron M. Renn (arenn@urbanophile.com)
6
/*
7
/* This program is free software; you can redistribute it and/or modify
8
/* it under the terms of the GNU General Public License as published
9
/* by the Free Software Foundation, either version 2 of the License, or
10
/* (at your option) any later version.
11
/*
12
/* This program is distributed in the hope that it will be useful, but
13
/* WITHOUT ANY WARRANTY; without even the implied warranty of
14
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
/* GNU General Public License for more details.
16
/*
17
/* You should have received a copy of the GNU General Public License
18
/* along with this program; if not, write to the Free Software Foundation
19
/* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
20
/*************************************************************************/
21
 
22
import java.io.*;
23
 
24
public class PipedStreamTest
25
{
26
 
27
public static void
28
main(String[] argv) throws InterruptedException
29
{
30
  // Set up a reasonable buffer size for this test if one is not already
31
  // specified
32
  String prop = System.getProperty("gnu.java.io.pipe_size");
33
//  if (prop == null)
34
//    System.setProperty("gnu.java.io.pipe_size", "32");
35
 
36
  try
37
    {
38
      System.out.println("Started test of PipedInputStream and " +
39
                         "PipedOutputStream");
40
 
41
      System.out.println("Test 1: Basic piped stream test");
42
 
43
      // Set up the thread to write
44
      PipedStreamTestWriter pstw = new PipedStreamTestWriter();
45
      String str = pstw.getStr();
46
      PipedOutputStream pos = pstw.getStream();
47
 
48
      // Now set up our reader
49
      PipedInputStream pis = new PipedInputStream();
50
      pis.connect(pos);
51
      new Thread(pstw).start();
52
 
53
      byte[] buf = new byte[12];
54
      int bytes_read, total_read = 0;
55
      while((bytes_read = pis.read(buf)) != -1)
56
        {
57
          System.out.print(new String(buf, 0, bytes_read));
58
          System.out.flush();
59
          Thread.sleep(10); // A short delay
60
          total_read += bytes_read;
61
        }
62
 
63
      if (total_read == str.length())
64
        System.out.println("PASSED: Basic piped stream test");
65
      else
66
        System.out.println("FAILED: Basic piped stream test");
67
    }
68
  catch (IOException e)
69
    {
70
      System.out.println("FAILED: Basic piped stream test: " + e);
71
    }
72
}
73
 
74
} // class PipedStreamTest
75
 
76
class PipedStreamTestWriter implements Runnable
77
{
78
 
79
String str;
80
StringBufferInputStream sbis;
81
PipedOutputStream out;
82
 
83
public
84
PipedStreamTestWriter()
85
{
86
  str = "I went to work for Andersen Consulting after I graduated\n" +
87
     "from college.  They sent me to their training facility in St. Charles,\n" +
88
     "Illinois and tried to teach me COBOL.  I didn't want to learn it.\n" +
89
     "The instructors said I had a bad attitude and I got a green sheet\n" +
90
     "which is a nasty note in your file saying what a jerk you are.\n";
91
 
92
  sbis = new StringBufferInputStream(str);
93
 
94
  out = new PipedOutputStream();
95
}
96
 
97
public PipedOutputStream
98
getStream()
99
{
100
  return(out);
101
}
102
 
103
public String
104
getStr()
105
{
106
  return(str);
107
}
108
 
109
public void
110
run()
111
{
112
  byte[] buf = new byte[32];
113
 
114
  int bytes_read;
115
 
116
  try
117
    {
118
      int b = sbis.read();
119
      out.write(b);
120
 
121
      while ((bytes_read = sbis.read(buf)) != -1)
122
        out.write(buf, 0, bytes_read);
123
 
124
      out.close();
125
    }
126
  catch(IOException e)
127
    {
128
      System.out.println("FAILED: Basic piped stream test: " + e);
129
    }
130
 
131
}
132
 
133
}
134
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.