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/] [PipedReaderWriterTest.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/*************************************************************************
2
/* PipedReaderWriterTest.java -- Tests Piped{Reader,Writers}'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 PipedReaderWriterTest
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 PipedReader and PipedWriter");
39
 
40
      System.out.println("Test 1: Basic pipe test");
41
 
42
      // Set up the thread to write
43
      PipedTestWriter ptw = new PipedTestWriter();
44
      String str = ptw.getStr();
45
      PipedWriter pw = ptw.getWriter();
46
 
47
      // Now set up our reader
48
      PipedReader pr = new PipedReader();
49
      pr.connect(pw);
50
      new Thread(ptw).start();
51
 
52
      char[] buf = new char[12];
53
      int chars_read, total_read = 0;
54
      while((chars_read = pr.read(buf)) != -1)
55
        {
56
          System.out.print(new String(buf, 0, chars_read));
57
          System.out.flush();
58
          Thread.sleep(10); // A short delay
59
          total_read += chars_read;
60
        }
61
 
62
      if (total_read == str.length())
63
        System.out.println("PASSED: Basic pipe test");
64
      else
65
        System.out.println("FAILED: Basic pipe test");
66
    }
67
  catch (IOException e)
68
    {
69
      System.out.println("FAILED: Basic pipe test: " + e);
70
    }
71
}
72
 
73
} // class PipedReaderWriterTest
74
 
75
class PipedTestWriter implements Runnable
76
{
77
 
78
String str;
79
StringReader sbr;
80
PipedWriter out;
81
 
82
public
83
PipedTestWriter()
84
{
85
  str = "In college, there was a tradition going for a while that people\n" +
86
    "would get together and hang out at Showalter Fountain - in the center\n" +
87
    "of Indiana University's campus - around midnight.  It was mostly folks\n" +
88
    "from the computer lab and just people who liked to use the Forum\n" +
89
    "bbs system on the VAX.  IU pulled the plug on the Forum after I left\n" +
90
    "despite its huge popularity.  Now they claim they are just giving\n" +
91
    "students what they want by cutting deals to make the campus all\n" +
92
    "Microsoft.\n";
93
 
94
  sbr = new StringReader(str);
95
 
96
  out = new PipedWriter();
97
}
98
 
99
public PipedWriter
100
getWriter()
101
{
102
  return(out);
103
}
104
 
105
public String
106
getStr()
107
{
108
  return(str);
109
}
110
 
111
public void
112
run()
113
{
114
  char[] buf = new char[32];
115
 
116
  int chars_read;
117
 
118
  try
119
    {
120
      int b = sbr.read();
121
      out.write(b);
122
 
123
      while ((chars_read = sbr.read(buf)) != -1)
124
        out.write(buf, 0, chars_read);
125
 
126
      out.close();
127
    }
128
  catch(IOException e)
129
    {
130
      System.out.println("FAILED: Basic pipe test: " + e);
131
    }
132
 
133
}
134
 
135
} // PipedTestWriter
136
 

powered by: WebSVN 2.1.0

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