diff options
Diffstat (limited to 'java/io')
-rw-r--r-- | java/io/FileDescriptor.java | 2 | ||||
-rw-r--r-- | java/io/FileInputStream.java | 20 | ||||
-rw-r--r-- | java/io/FileOutputStream.java | 26 | ||||
-rw-r--r-- | java/io/InputStreamReader.java | 2 | ||||
-rw-r--r-- | java/io/ObjectStreamClass.java | 4 | ||||
-rw-r--r-- | java/io/PipedInputStream.java | 4 | ||||
-rw-r--r-- | java/io/PipedReader.java | 4 | ||||
-rw-r--r-- | java/io/RandomAccessFile.java | 17 |
8 files changed, 65 insertions, 14 deletions
diff --git a/java/io/FileDescriptor.java b/java/io/FileDescriptor.java index dd3db1c74..cf9ff20d5 100644 --- a/java/io/FileDescriptor.java +++ b/java/io/FileDescriptor.java @@ -39,7 +39,7 @@ exception statement from your version. */ package java.io; -import gnu.java.nio.channels.FileChannelImpl; +import gnu.java.nio.FileChannelImpl; import java.nio.channels.ByteChannel; import java.nio.channels.FileChannel; diff --git a/java/io/FileInputStream.java b/java/io/FileInputStream.java index 8ca38b02f..8217668b4 100644 --- a/java/io/FileInputStream.java +++ b/java/io/FileInputStream.java @@ -38,8 +38,9 @@ exception statement from your version. */ package java.io; -import gnu.java.nio.channels.FileChannelImpl; +import gnu.java.nio.FileChannelImpl; +import java.nio.ByteBuffer; import java.nio.channels.FileChannel; /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 @@ -107,7 +108,20 @@ public class FileInputStream extends InputStream if (s != null) s.checkRead(file.getPath()); - ch = FileChannelImpl.create(file, FileChannelImpl.READ); + try + { + ch = FileChannelImpl.create(file, FileChannelImpl.READ); + } + catch (FileNotFoundException fnfe) + { + throw fnfe; + } + catch (IOException ioe) + { + FileNotFoundException fnfe = new FileNotFoundException(file.getPath()); + fnfe.initCause(ioe); + throw fnfe; + } } /** @@ -266,7 +280,7 @@ public class FileInputStream extends InputStream || offset + len > buf.length) throw new ArrayIndexOutOfBoundsException(); - return ch.read(buf, offset, len); + return ch.read(ByteBuffer.wrap(buf, offset, len)); } /** diff --git a/java/io/FileOutputStream.java b/java/io/FileOutputStream.java index 10ea6b536..d7561a9d7 100644 --- a/java/io/FileOutputStream.java +++ b/java/io/FileOutputStream.java @@ -38,8 +38,9 @@ exception statement from your version. */ package java.io; -import gnu.java.nio.channels.FileChannelImpl; +import gnu.java.nio.FileChannelImpl; +import java.nio.ByteBuffer; import java.nio.channels.FileChannel; /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 @@ -155,10 +156,23 @@ public class FileOutputStream extends OutputStream if (s != null) s.checkWrite(file.getPath()); - ch = FileChannelImpl.create(file, (append - ? FileChannelImpl.WRITE - | FileChannelImpl.APPEND - : FileChannelImpl.WRITE)); + try + { + ch = FileChannelImpl.create(file, (append + ? FileChannelImpl.WRITE + | FileChannelImpl.APPEND + : FileChannelImpl.WRITE)); + } + catch (FileNotFoundException fnfe) + { + throw fnfe; + } + catch (IOException ioe) + { + FileNotFoundException fnfe = new FileNotFoundException(file.getPath()); + fnfe.initCause(ioe); + throw fnfe; + } } /** @@ -266,7 +280,7 @@ public class FileOutputStream extends OutputStream || offset + len > buf.length) throw new ArrayIndexOutOfBoundsException (); - ch.write (buf, offset, len); + ch.write(ByteBuffer.wrap(buf, offset, len)); } /** diff --git a/java/io/InputStreamReader.java b/java/io/InputStreamReader.java index 8d97799d5..6c5297f6b 100644 --- a/java/io/InputStreamReader.java +++ b/java/io/InputStreamReader.java @@ -368,6 +368,8 @@ public class InputStreamReader extends Reader if(decoder != null) { int totalBytes = (int)((double) length * maxBytesPerChar); + if (byteBuffer != null) + totalBytes = Math.max(totalBytes, byteBuffer.remaining()); byte[] bytes; // Fetch cached bytes array if available and big enough. synchronized(cacheLock) diff --git a/java/io/ObjectStreamClass.java b/java/io/ObjectStreamClass.java index 21a80c392..52a1ad428 100644 --- a/java/io/ObjectStreamClass.java +++ b/java/io/ObjectStreamClass.java @@ -323,8 +323,8 @@ public class ObjectStreamClass implements Serializable else { // Check that the actual UID of the resolved class matches the UID from - // the stream. - if (uid != class_uid) + // the stream. Mismatches for array classes are ignored. + if (!cl.isArray() && uid != class_uid) { String msg = cl + ": Local class not compatible: stream serialVersionUID=" diff --git a/java/io/PipedInputStream.java b/java/io/PipedInputStream.java index 523ae2c70..c0396d206 100644 --- a/java/io/PipedInputStream.java +++ b/java/io/PipedInputStream.java @@ -279,6 +279,10 @@ public class PipedInputStream extends InputStream if (closed) throw new IOException ("Pipe closed"); + // Don't block if nothing was requested. + if (len == 0) + return 0; + // If the buffer is empty, wait until there is something in the pipe // to read. try diff --git a/java/io/PipedReader.java b/java/io/PipedReader.java index 90fc10f67..8a3363a60 100644 --- a/java/io/PipedReader.java +++ b/java/io/PipedReader.java @@ -261,6 +261,10 @@ public class PipedReader extends Reader if (closed) throw new IOException ("Pipe closed"); + // Don't block if nothing was requested. + if (len == 0) + return 0; + // If the buffer is empty, wait until there is something in the pipe // to read. try diff --git a/java/io/RandomAccessFile.java b/java/io/RandomAccessFile.java index d719a1e3b..036fc8c6b 100644 --- a/java/io/RandomAccessFile.java +++ b/java/io/RandomAccessFile.java @@ -38,7 +38,7 @@ exception statement from your version. */ package java.io; -import gnu.java.nio.channels.FileChannelImpl; +import gnu.java.nio.FileChannelImpl; import java.nio.channels.FileChannel; @@ -122,7 +122,20 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable s.checkWrite(fileName); } - ch = FileChannelImpl.create(file, fdmode); + try + { + ch = FileChannelImpl.create(file, fdmode); + } + catch (FileNotFoundException fnfe) + { + throw fnfe; + } + catch (IOException ioe) + { + FileNotFoundException fnfe = new FileNotFoundException(file.getPath()); + fnfe.initCause(ioe); + throw fnfe; + } fd = new FileDescriptor(ch); if ((fdmode & FileChannelImpl.WRITE) != 0) out = new DataOutputStream (new FileOutputStream (fd)); |