diff options
author | Per Bothner <per@bothner.com> | 2002-02-22 05:53:23 -0800 |
---|---|---|
committer | Per Bothner <bothner@gcc.gnu.org> | 2002-02-22 05:53:23 -0800 |
commit | 0bf188159d50fe4a16a6fed99e67b00decb44372 (patch) | |
tree | 403487f3054f73980bce2587de7b1ce07c86d4f2 /libjava/gnu | |
parent | 696179ca62f0ae83ed5b86100d683b60dc83eb97 (diff) | |
download | gcc-0bf188159d50fe4a16a6fed99e67b00decb44372.zip gcc-0bf188159d50fe4a16a6fed99e67b00decb44372.tar.gz gcc-0bf188159d50fe4a16a6fed99e67b00decb44372.tar.bz2 |
Connection.java (conect): Open the input and/or output streams immediately here, instead of using File.exists.
* gnu/gcj/protocol/file/Connection.java (conect): Open the input
and/or output streams immediately here, instead of using File.exists.
(inputStream, outputStream): New fields to save open streams.
(getInputStream, getOutputStream): Use already-opened streams.
From-SVN: r49965
Diffstat (limited to 'libjava/gnu')
-rw-r--r-- | libjava/gnu/gcj/protocol/file/Connection.java | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/libjava/gnu/gcj/protocol/file/Connection.java b/libjava/gnu/gcj/protocol/file/Connection.java index e9ef08f..5510c5d 100644 --- a/libjava/gnu/gcj/protocol/file/Connection.java +++ b/libjava/gnu/gcj/protocol/file/Connection.java @@ -33,6 +33,8 @@ class Connection extends URLConnection private Vector hdrVec = new Vector(); private boolean gotHeaders = false; private File fileIn; + private InputStream inputStream; + private OutputStream outputStream; public Connection(URL url) { @@ -47,34 +49,36 @@ class Connection extends URLConnection return; // If not connected, then file needs to be openned. - fileIn = new File(url.getFile()); - - if (fileIn.exists()) - connected = true; - else - throw new FileNotFoundException("No such file or directory"); + String fname = url.getFile(); + fileIn = new File(fname); + if (doInput) + inputStream = new BufferedInputStream(new FileInputStream(fileIn)); + if (doOutput) + outputStream = new BufferedOutputStream(new FileOutputStream(fileIn)); + connected = true; } public InputStream getInputStream() throws IOException { + if (! doInput) + throw new ProtocolException("Can't open InputStream if doInput is false"); if (!connected) connect(); - if (! doInput) - throw new ProtocolException("Can't open InputStream if doInput is false"); - return new BufferedInputStream(new FileInputStream(fileIn)); + return inputStream; } // Override default method in URLConnection. public OutputStream getOutputStream() throws IOException { - if (!connected) - connect(); - if (! doOutput) throw new ProtocolException("Can't open OutputStream if doOutput is false"); - return new BufferedOutputStream(new FileOutputStream(fileIn)); + + if (!connected) + connect(); + + return outputStream; } // Override default method in URLConnection. |