/[classpath]/classpath/java/io/RandomAccessFile.java
ViewVC logotype

Diff of /classpath/java/io/RandomAccessFile.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.21 by mkoch, Mon Mar 24 07:27:52 2003 UTC revision 1.22 by mkoch, Mon Mar 24 10:19:19 2003 UTC
# Line 178  public class RandomAccessFile implements Line 178  public class RandomAccessFile implements
178    }    }
179        
180    /**    /**
    * This method returns the length of the file in bytes  
    *  
    * @return The length of the file  
    *  
    * @exception IOException If an error occurs  
    */  
   public long length() throws IOException  
   {  
     return(fd.getLength());  
   }  
     
   /**  
    * This method sets the current file position to the specified offset  
    * from the beginning of the file.  Note that some operating systems will  
    * allow the file pointer to be set past the current end of the file.  
    *  
    * @param pos The offset from the beginning of the file at which to set  
    * the file pointer  
    *  
    * @exception IOException If an error occurs  
    */  
   public void seek(long pos) throws IOException  
   {  
     fd.seek(pos, fd.SET, false);  
   }  
     
   /**  
181     * This method sets the length of the file to the specified length.  If     * This method sets the length of the file to the specified length.  If
182     * the currently length of the file is longer than the specified length,     * the currently length of the file is longer than the specified length,
183     * then the file is truncated to the specified length.  If the current     * then the file is truncated to the specified length.  If the current
# Line 226  public class RandomAccessFile implements Line 199  public class RandomAccessFile implements
199    }    }
200        
201    /**    /**
202       * This method returns the length of the file in bytes
203       *
204       * @return The length of the file
205       *
206       * @exception IOException If an error occurs
207       */
208      public long length() throws IOException
209      {
210        return(fd.getLength());
211      }
212      
213      /**
214      * This method reads a single byte of data from the file and returns it      * This method reads a single byte of data from the file and returns it
215      * as an integer.      * as an integer.
216      *      *
# Line 555  public class RandomAccessFile implements Line 540  public class RandomAccessFile implements
540    }    }
541        
542    /**    /**
543       * This method reads raw bytes into the passed array until the array is
544       * full.  Note that this method blocks until the data is available and
545       * throws an exception if there is not enough data left in the stream to
546       * fill the buffer
547       *
548       * @param buf The buffer into which to read the data
549       *
550       * @exception EOFException If end of file is reached before filling the
551       * buffer
552       * @exception IOException If any other error occurs
553       */
554      public final void readFully(byte[] buf) throws EOFException, IOException
555      {
556        readFully(buf, 0, buf.length);
557      }
558      
559      /**
560       * This method reads raw bytes into the passed array <code>buf</code>
561       * starting
562       * <code>offset</code> bytes into the buffer.  The number of bytes read
563       * will be
564       * exactly <code>len</code>  Note that this method blocks until the data is
565       * available and throws an exception if there is not enough data left in
566       * the stream to read <code>len</code> bytes.
567       *
568       * @param buf The buffer into which to read the data
569       * @param offset The offset into the buffer to start storing data
570       * @param len The number of bytes to read into the buffer
571       *
572       * @exception EOFException If end of file is reached before filling
573       * the buffer
574       * @exception IOException If any other error occurs
575       */
576      public synchronized final void readFully(byte[] buf, int offset, int len)
577        throws EOFException, IOException
578      {
579        int total_read = 0;
580      
581        while (total_read < len)
582          {
583            int bytes_read = read(buf, offset + total_read, len - total_read);
584            if (bytes_read == -1)
585              throw new EOFException("Unexpected end of stream");
586      
587            total_read += bytes_read;
588          }
589      }
590      
591      /**
592     * This method reads a Java double value from an input stream.  It operates     * This method reads a Java double value from an input stream.  It operates
593     * by first reading a <code>logn</code> value from the stream by calling the     * by first reading a <code>logn</code> value from the stream by calling the
594     * <code>readLong()</code> method in this interface, then     * <code>readLong()</code> method in this interface, then
# Line 725  public class RandomAccessFile implements Line 759  public class RandomAccessFile implements
759    }    }
760        
761    /**    /**
762     * This method reads raw bytes into the passed array until the array is     * This method sets the current file position to the specified offset
763     * full.  Note that this method blocks until the data is available and     * from the beginning of the file.  Note that some operating systems will
764     * throws an exception if there is not enough data left in the stream to     * allow the file pointer to be set past the current end of the file.
    * fill the buffer  
    *  
    * @param buf The buffer into which to read the data  
    *  
    * @exception EOFException If end of file is reached before filling the  
    * buffer  
    * @exception IOException If any other error occurs  
    */  
   public final void readFully(byte[] buf) throws EOFException, IOException  
   {  
     readFully(buf, 0, buf.length);  
   }  
     
   /**  
    * This method reads raw bytes into the passed array <code>buf</code>  
    * starting  
    * <code>offset</code> bytes into the buffer.  The number of bytes read  
    * will be  
    * exactly <code>len</code>  Note that this method blocks until the data is  
    * available and throws an exception if there is not enough data left in  
    * the stream to read <code>len</code> bytes.  
765     *     *
766     * @param buf The buffer into which to read the data     * @param pos The offset from the beginning of the file at which to set
767     * @param offset The offset into the buffer to start storing data     * the file pointer
    * @param len The number of bytes to read into the buffer  
768     *     *
769     * @exception EOFException If end of file is reached before filling     * @exception IOException If an error occurs
    * the buffer  
    * @exception IOException If any other error occurs  
770     */     */
771    public synchronized final void readFully(byte[] buf, int offset, int len)    public void seek(long pos) throws IOException
     throws EOFException, IOException  
772    {    {
773      int total_read = 0;      fd.seek(pos, fd.SET, false);
     
     while (total_read < len)  
       {  
         int bytes_read = read(buf, offset + total_read, len - total_read);  
         if (bytes_read == -1)  
           throw new EOFException("Unexpected end of stream");  
     
         total_read += bytes_read;  
       }  
774    }    }
775        
776    /**    /**

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26