01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.debug.jdi.tests;
11:
12: import java.io.BufferedReader;
13: import java.io.File;
14: import java.io.FileOutputStream;
15: import java.io.IOException;
16: import java.io.InputStream;
17: import java.io.InputStreamReader;
18:
19: /**
20: * Tests continuous reading from a file and input stream
21: */
22: public class FileConsoleReader extends AbstractReader {
23: private InputStream fInput;
24: private FileOutputStream fFileOutputStream;
25:
26: /**
27: * Creates a new console reader that will read from the given input stream.
28: * @param name
29: * @param fileName
30: * @param input
31: */
32: public FileConsoleReader(String name, String fileName,
33: InputStream input) {
34: super (name);
35: fInput = input;
36: try {
37: fFileOutputStream = new FileOutputStream(new File(fileName));
38: } catch (IOException e) {
39: System.out.println("Got exception: " + e.getMessage());
40: }
41: }
42:
43: /**
44: * Continuously reads events that are coming from the event queue.
45: */
46: protected void readerLoop() {
47: BufferedReader input = new BufferedReader(
48: new InputStreamReader(fInput));
49: try {
50: int read = 0;
51: while (!fIsStopping && read != -1) {
52: read = input.read();
53: if (read != -1) {
54: fFileOutputStream.write(read);
55: }
56: fFileOutputStream.flush();
57: }
58: } catch (IOException e) {
59: }
60: }
61:
62: /**
63: * @see org.eclipse.debug.jdi.tests.AbstractReader#stop()
64: */
65: public void stop() {
66: try {
67: fFileOutputStream.close();
68: } catch (IOException e) {
69: System.out.println("Got exception: " + e.getMessage());
70: }
71: }
72: }
|