mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-11-29 23:04:12 +08:00
2004-09-10 Michael Koch <konqueror@gmx.de>
* gnu/java/net/protocol/file/Connection.java (lineSeparator): Made non-final. (static): Removed. (connect): Initialize lineSeparator lazily. Use ByteArrayInputStream instead of StringBufferInputStream. 2004-09-10 Michael Koch <konqueror@gmx.de> * gnu/java/net/protocol/file/Connection.java (connect): Handle file is a directory case. From-SVN: r87279
This commit is contained in:
parent
456d47b390
commit
5123971af8
@ -1,3 +1,16 @@
|
||||
2004-09-10 Michael Koch <konqueror@gmx.de>
|
||||
|
||||
* gnu/java/net/protocol/file/Connection.java
|
||||
(lineSeparator): Made non-final.
|
||||
(static): Removed.
|
||||
(connect): Initialize lineSeparator lazily. Use ByteArrayInputStream
|
||||
instead of StringBufferInputStream.
|
||||
|
||||
2004-09-10 Michael Koch <konqueror@gmx.de>
|
||||
|
||||
* gnu/java/net/protocol/file/Connection.java
|
||||
(connect): Handle file is a directory case.
|
||||
|
||||
2004-09-10 Michael Koch <konqueror@gmx.de>
|
||||
|
||||
* Makefile.am
|
||||
|
@ -37,8 +37,11 @@ exception statement from your version. */
|
||||
|
||||
package gnu.java.net.protocol.file;
|
||||
|
||||
import gnu.java.security.action.GetPropertyAction;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
@ -50,6 +53,7 @@ import java.net.ProtocolException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.security.Permission;
|
||||
import java.security.AccessController;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
@ -71,6 +75,8 @@ public class Connection extends URLConnection
|
||||
= new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'",
|
||||
new Locale ("En", "Us", "Unix"));
|
||||
|
||||
private static String lineSeparator;
|
||||
|
||||
/**
|
||||
* This is a File object for this connection
|
||||
*/
|
||||
@ -105,11 +111,38 @@ public class Connection extends URLConnection
|
||||
|
||||
// If not connected, then file needs to be openned.
|
||||
file = new File (getURL().getFile());
|
||||
if (doInput)
|
||||
inputStream = new BufferedInputStream(new FileInputStream(file));
|
||||
|
||||
if (! file.isDirectory())
|
||||
{
|
||||
if (doInput)
|
||||
inputStream = new BufferedInputStream(new FileInputStream(file));
|
||||
|
||||
if (doOutput)
|
||||
outputStream = new BufferedOutputStream(new FileOutputStream(file));
|
||||
if (doOutput)
|
||||
outputStream = new BufferedOutputStream(new FileOutputStream(file));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (doInput)
|
||||
{
|
||||
if (lineSeparator == null)
|
||||
{
|
||||
GetPropertyAction getProperty = new GetPropertyAction("line.separator");
|
||||
lineSeparator = (String) AccessController.doPrivileged(getProperty);
|
||||
}
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String[] files = file.list();
|
||||
|
||||
for (int index = 0; index < files.length; ++index)
|
||||
sb.append(files[index]).append(lineSeparator);
|
||||
|
||||
inputStream = new ByteArrayInputStream(sb.toString().getBytes());
|
||||
}
|
||||
|
||||
if (doOutput)
|
||||
throw new ProtocolException
|
||||
("file: protocol does not support output on directories");
|
||||
}
|
||||
|
||||
connected = true;
|
||||
}
|
||||
@ -184,6 +217,7 @@ public class Connection extends URLConnection
|
||||
|
||||
/**
|
||||
* Get the length of content.
|
||||
*
|
||||
* @return the length of the content.
|
||||
*/
|
||||
public int getContentLength()
|
||||
@ -212,7 +246,7 @@ public class Connection extends URLConnection
|
||||
{
|
||||
if (!connected)
|
||||
connect();
|
||||
|
||||
|
||||
return file.lastModified();
|
||||
}
|
||||
catch (IOException e)
|
||||
@ -220,7 +254,7 @@ public class Connection extends URLConnection
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method returns a <code>Permission</code> object representing the
|
||||
* permissions required to access this URL. This method returns a
|
||||
|
Loading…
Reference in New Issue
Block a user