This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

shutdownInput, shutdownOutput, setLength


java/io/FileDescriptor.shutdownInput,shutdownOutput
java/io/RandomAccessFile.setLength


Index: FileDescriptor.java
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/io/FileDescriptor.java,v
retrieving revision 1.9
diff -c -r1.9 FileDescriptor.java
*** FileDescriptor.java	6 Mar 2002 22:37:26 -0000	1.9
--- FileDescriptor.java	4 Jul 2002 04:03:29 -0000
***************
*** 65,70 ****
--- 65,73 ----
    native void write (byte[] b, int offset, int len)
      throws IOException, NullPointerException, IndexOutOfBoundsException;
    native void close () throws IOException;
+   native void shutdownInput () throws IOException;
+   native void shutdownOutput () throws IOException;
+   native void setLength (long pos) throws IOException;
    // EOF_TRUNC is true if a request to seek past the end of file
    // should actually stop at the end of file.  If false, then a seek
    // past the end is ok (and if a subsequent write occurs the file
Index: RandomAccessFile.java
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/io/RandomAccessFile.java,v
retrieving revision 1.6
diff -c -r1.6 RandomAccessFile.java
*** RandomAccessFile.java	2 Aug 2001 23:46:39 -0000	1.6
--- RandomAccessFile.java	4 Jul 2002 04:03:29 -0000
***************
*** 40,45 ****
--- 40,51 ----
      return fd.getFilePointer();
    }
  
+   public void setLength (long pos) throws IOException
+   {
+     fd.setLength(pos);
+     return;
+   }
+ 
    public long length () throws IOException
    {
      return fd.length();
Index: natFileDescriptorEcos.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/io/natFileDescriptorEcos.cc,v
retrieving revision 1.8
diff -c -r1.8 natFileDescriptorEcos.cc
*** natFileDescriptorEcos.cc	6 Mar 2002 23:23:34 -0000	1.8
--- natFileDescriptorEcos.cc	4 Jul 2002 04:03:29 -0000
***************
*** 95,100 ****
--- 95,115 ----
  {
  }
  
+ void
+ java::io::FileDescriptor::shutdownInput (void)
+ {
+ }
+ 
+ void
+ java::io::FileDescriptor::shutdownOutput (void)
+ {
+ }
+ 
+ void
+ java::io::FileDescriptor::setLength (void)
+ {
+ }
+ 
  jint
  java::io::FileDescriptor::seek (jlong pos, jint whence, jboolean)
  {
Index: natFileDescriptorPosix.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/io/natFileDescriptorPosix.cc,v
retrieving revision 1.19
diff -c -r1.19 natFileDescriptorPosix.cc
*** natFileDescriptorPosix.cc	10 Mar 2002 17:59:23 -0000	1.19
--- natFileDescriptorPosix.cc	4 Jul 2002 04:03:29 -0000
***************
*** 17,22 ****
--- 17,24 ----
  #include <string.h>
  #include <sys/stat.h>
  #include <sys/param.h>
+ #include <sys/socket.h>
+ #include <fcntl.h>
  
  #ifdef HAVE_SYS_IOCTL_H
  #define BSD_COMP /* Get FIONREAD on Solaris2. */
***************
*** 187,192 ****
--- 189,238 ----
    fd = -1;
    if (::close (save))
      throw new IOException (JvNewStringLatin1 (strerror (errno)));
+ }
+ 
+ void
+ java::io::FileDescriptor::shutdownInput (void)
+ {
+   if (::shutdown(fd,0))
+     throw new IOException (JvNewStringLatin1 (strerror (errno)));
+ }
+ 
+ void
+ java::io::FileDescriptor::shutdownOutput (void)
+ {
+   if (::shutdown(fd,1))
+     throw new IOException (JvNewStringLatin1 (strerror (errno)));
+ }
+ 
+ void
+ java::io::FileDescriptor::setLength (jlong pos)
+ {
+   struct stat sb;
+   off_t orig;
+ 
+   if (::fstat (fd, &sb))
+     throw new IOException (JvNewStringLatin1 (strerror (errno)));
+ 
+   if ((jlong)sb.st_size == pos) 
+     return;
+   
+   orig = ::lseek(fd, (off_t) 0, SEEK_CUR);
+   if (orig == -1)
+     throw new IOException (JvNewStringLatin1 (strerror (errno)));
+ 
+   if ((jlong)sb.st_size < pos) {
+     if (::lseek(fd, (off_t)pos, SEEK_SET) == -1) 
+       throw new IOException (JvNewStringLatin1 (strerror (errno)));
+     if (::lseek(fd, orig, SEEK_SET) == -1) 
+       throw new IOException (JvNewStringLatin1 (strerror (errno)));
+     return;
+   } 
+ 
+   if (::ftruncate (fd, (off_t) pos))
+     throw new IOException (JvNewStringLatin1 (strerror (errno)));
+ 
+   return;
  }
  
  jint
Index: natFileDescriptorWin32.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/io/natFileDescriptorWin32.cc,v
retrieving revision 1.9
diff -c -r1.9 natFileDescriptorWin32.cc
*** natFileDescriptorWin32.cc	6 Jun 2002 20:39:37 -0000	1.9
--- natFileDescriptorWin32.cc	4 Jul 2002 04:03:30 -0000
***************
*** 186,191 ****
--- 186,252 ----
      throw new IOException (JvNewStringLatin1 (winerr ()));
  }
  
+ void
+ java::io::FileDescriptor::shutdownInput (void)
+ {
+   if (shutdown((SOCKET)fd,SD_RECEIVE,&err) != 0)
+     throw new IOException (JvNewStringLatin1 (winerr ()));
+ }
+ 
+ void
+ java::io::FileDescriptor::shutdownOutput (void)
+ {
+   if (shutdown((SOCKET)fd,SD_SEND,&err) != 0)
+     JvThrow (new IOException (JvNewStringLatin1 (winerr ())));
+     throw new IOException (JvNewStringLatin1 (winerr ()));
+ }
+ 
+ void
+ java::io::FileDescriptor::setLength(jlong pos)
+ {
+   LONG_INTEGER liOrigFilePointer;
+   LONG_INTEGER liNewFilePointer;
+   LONG_INTEGER liEndFilePointer;
+ 
+   // get the original file pointer
+   if (SetFilePointerEx((HANDLE)fd, (LONG_INTEGER)0, &liOrigFilePointer, FILE_CURRENT) != (BOOL)0
+       && (GetLastError() != NO_ERROR)) 
+     throw new IOException (JvNewStringLatin1 (winerr ()));
+   
+   // get the length of the file
+   if (SetFilePointerEx((HANDLE)fd, (LONG_INTEGER)0, &liEndFilePointer, FILE_END) != (BOOL)0
+       && (GetLastError() != NO_ERROR)) 
+     throw new IOException (JvNewStringLatin1 (winerr ()));
+   
+   if ((jlong)liEndFilePointer == pos) {
+     // restore the file pointer
+     if (liOrigFilePointer != liEndFilePointer) {
+       if (SetFilePointerEx((HANDLE)fd, liOrigFilePointer, &liNewFilePointer, FILE_BEGIN) != (BOOL)0
+           && (GetLastError() != NO_ERROR)) 
+         throw new IOException (JvNewStringLatin1 (winerr ()));
+     }
+     return;
+   }
+ 
+   // seek to the new end of file
+   if (SetFilePointerEx((HANDLE)fd, (LONG_INTEGER)pos, &liNewFilePointer, FILE_BEGIN) != (BOOL)0
+       && (GetLastError() != NO_ERROR)) 
+     throw new IOException (JvNewStringLatin1 (winerr ()));
+       
+   // truncate the file at this point
+   if (SetEndOfFile((HANDLE)fd) != (BOOL)0 && (GetLastError() != NO_ERROR)) 
+     throw new IOException (JvNewStringLatin1 (winerr ()));
+   
+   if (liOrigFilePointer < liNewFilePointer) {
+     // restore the file pointer
+     if (SetFilePointerEx((HANDLE)fd, liOrigFilePointer, &liNewFilePointer, FILE_BEGIN) != (BOOL)0
+         && (GetLastError() != NO_ERROR)) 
+       throw new IOException (JvNewStringLatin1 (winerr ()));
+   }
+ 
+   return;
+ }
+ 
  jint
  java::io::FileDescriptor::seek (jlong pos, jint whence, jboolean eof_trunc)
  {


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]