Commit 0bf18815 by Per Bothner Committed by Per Bothner

Connection.java (conect): Open the input and/or output streams immediately here,…

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
parent 696179ca
2002-02-20 Per Bothner <per@bothner.com>
* 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.
2002-02-22 Alexandre Oliva <aoliva@redhat.com> 2002-02-22 Alexandre Oliva <aoliva@redhat.com>
* acinclude.m4 (LIB_AC_PROG_CXX): Copied from libstdc++-v3. * acinclude.m4 (LIB_AC_PROG_CXX): Copied from libstdc++-v3.
......
...@@ -33,6 +33,8 @@ class Connection extends URLConnection ...@@ -33,6 +33,8 @@ class Connection extends URLConnection
private Vector hdrVec = new Vector(); private Vector hdrVec = new Vector();
private boolean gotHeaders = false; private boolean gotHeaders = false;
private File fileIn; private File fileIn;
private InputStream inputStream;
private OutputStream outputStream;
public Connection(URL url) public Connection(URL url)
{ {
...@@ -47,34 +49,36 @@ class Connection extends URLConnection ...@@ -47,34 +49,36 @@ class Connection extends URLConnection
return; return;
// If not connected, then file needs to be openned. // If not connected, then file needs to be openned.
fileIn = new File(url.getFile()); String fname = url.getFile();
fileIn = new File(fname);
if (fileIn.exists()) if (doInput)
connected = true; inputStream = new BufferedInputStream(new FileInputStream(fileIn));
else if (doOutput)
throw new FileNotFoundException("No such file or directory"); outputStream = new BufferedOutputStream(new FileOutputStream(fileIn));
connected = true;
} }
public InputStream getInputStream() throws IOException public InputStream getInputStream() throws IOException
{ {
if (! doInput)
throw new ProtocolException("Can't open InputStream if doInput is false");
if (!connected) if (!connected)
connect(); connect();
if (! doInput) return inputStream;
throw new ProtocolException("Can't open InputStream if doInput is false");
return new BufferedInputStream(new FileInputStream(fileIn));
} }
// Override default method in URLConnection. // Override default method in URLConnection.
public OutputStream getOutputStream() throws IOException public OutputStream getOutputStream() throws IOException
{ {
if (!connected)
connect();
if (! doOutput) if (! doOutput)
throw new throw new
ProtocolException("Can't open OutputStream if doOutput is false"); 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. // Override default method in URLConnection.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment