OSDN Git Service

* gnu/gcj/protocol/file/Connection.java (conect): Open the input
authorbothner <bothner@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 22 Feb 2002 13:53:23 +0000 (13:53 +0000)
committerbothner <bothner@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 22 Feb 2002 13:53:23 +0000 (13:53 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@49965 138bc75d-0d04-0410-961f-82ee72b054a4

libjava/ChangeLog
libjava/gnu/gcj/protocol/file/Connection.java

index c2132ab..903ca65 100644 (file)
@@ -1,3 +1,10 @@
+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>
 
        * acinclude.m4 (LIB_AC_PROG_CXX): Copied from libstdc++-v3.
index e9ef08f..5510c5d 100644 (file)
@@ -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.