KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > sendopts > Env


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.spi.sendopts;
21
22 import java.io.File JavaDoc;
23 import java.io.InputStream JavaDoc;
24 import java.io.OutputStream JavaDoc;
25 import java.io.PrintStream JavaDoc;
26
27 /** Represents the environment an {@link OptionProcessor} operates in. Streams can be
28  * used to read and write data provided by the user. It is also possible
29  * to obtain current user directory. In future this class may be extended
30  * with additional new getters that will describe the operating environment
31  * in greater detail.
32  *
33  * @author Jaroslav Tulach
34  */

35 public final class Env {
36     private InputStream JavaDoc is;
37     private PrintStream JavaDoc os;
38     private PrintStream JavaDoc err;
39     private File JavaDoc currentDir;
40
41     /** Creates a new instance of Env */
42     Env(InputStream JavaDoc is, OutputStream JavaDoc os, OutputStream JavaDoc err, File JavaDoc currentDir) {
43         this.is = is;
44         this.os = os instanceof PrintStream JavaDoc ? (PrintStream JavaDoc)os : new PrintStream JavaDoc(os);
45         this.err = err instanceof PrintStream JavaDoc ? (PrintStream JavaDoc)err : new PrintStream JavaDoc(err);
46         this.currentDir = currentDir;
47     }
48     
49     /**
50      * Get an output stream to which data may be sent.
51      * @return stream to write to
52      */

53     public PrintStream JavaDoc getOutputStream() {
54         return os;
55     }
56     /**
57      * Get an output stream to which error messages may be sent.
58      * @return stream to write to
59      */

60     public PrintStream JavaDoc getErrorStream() {
61         return err;
62     }
63
64     /**
65      * The directory relative file operations shall be relative to. Can
66      * be specified while starting the parse of {@link org.netbeans.api.sendopts.CommandLine}.
67      *
68      * @return file representing current directory
69      */

70     public File JavaDoc getCurrentDirectory () {
71         return currentDir;
72     }
73
74     /**
75      * Get an input stream that may supply additional data.
76      * @return stream to read from
77      */

78     public InputStream JavaDoc getInputStream() {
79         return is;
80     }
81 }
82
Popular Tags