superwaba.ext.xplat.io
Class BufferedFile

java.lang.Object
  |
  +--waba.io.Stream
        |
        +--waba.io.File
              |
              +--superwaba.ext.xplat.io.BufferedFile

public class BufferedFile
extends File

BufferedFile offers a faster way to read data from big files. Here's a test:

   int bytesRead=0;
   int fileSize;
   File file;
   DataStream ds;
   BufferedFile file = new BufferedFile(path, mode, buffSize);
   fileSize = file.getSize();
   bytesRead = 0;
   ds = new DataStream(file);
   while (bytesRead+4 < fileSize)
   {
      try
      {
         ds.readInt();
         bytesRead+=4;
      }
      catch (Exception e)
      {
         e.printStackTrace();
         break;
      }
   }
   file.close();
 

Since:
SuperWaba 5.51

Field Summary
 boolean eof
           
 
Fields inherited from class waba.io.File
ATTR_ARCHIVE, ATTR_HIDDEN, ATTR_READ_ONLY, ATTR_SYSTEM, CREATE, DONT_OPEN, lastError, path, READ_ONLY, READ_WRITE, TIME_ACCESSED, TIME_ALL, TIME_CREATED, TIME_MODIFIED, winceVols, WRITE_ONLY
 
Constructor Summary
BufferedFile(java.lang.String path, int mode)
          Opens a file with the given name and mode.
BufferedFile(java.lang.String path, int mode, int buffSize)
          Opens a file with the given name and mode.
 
Method Summary
 int readBytes(byte[] bytes, int off, int len)
          Reads bytes from the file into a byte array.
 void skip(int countBytes)
          Skips countBytes bytes
 
Methods inherited from class waba.io.File
close, createDir, delete, exists, finalize, getAttributes, getCardVolume, getPath, getSize, getTime, isAvailable, isCardInserted, isDir, isOpen, listFiles, rename, setAttributes, setPos, setTime, writeBytes
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

eof

public boolean eof
Constructor Detail

BufferedFile

public BufferedFile(java.lang.String path,
                    int mode,
                    int buffSize)
Opens a file with the given name and mode. If mode is CREATE, the file will be created if it does not exist. The DONT_OPEN mode allows the exists(), rename(), delete(), listDir(), createDir() and isDir() methods to be called without requiring the file to be open for reading or writing. Note that the filename must not contain accentuated characters. Also, the slash / MUST be the path separator. The size of the internal Buffer is set to buffSize
Parameters:
path - the file's path
mode - one of DONT_OPEN, READ_ONLY, WRITE_ONLY, READ_WRITE or CREATE
buffSize - size of the internal buffer

BufferedFile

public BufferedFile(java.lang.String path,
                    int mode)
Opens a file with the given name and mode. If mode is CREATE, the file will be created if it does not exist. The DONT_OPEN mode allows the exists(), rename(), delete(), listDir(), createDir() and isDir() methods to be called without requiring the file to be open for reading or writing. Note that the filename must not contain accentuated characters. Also, the slash / MUST be the path separator. The size of the internal Buffer is set to 1024
Parameters:
path - the file's path
mode - one of DONT_OPEN, READ_ONLY, WRITE_ONLY, READ_WRITE or CREATE
Method Detail

readBytes

public int readBytes(byte[] bytes,
                     int off,
                     int len)
Reads bytes from the file into a byte array. Returns the number of bytes actually read or -1 if an error prevented the read operation from occurring. After the read is complete, the location of the file pointer (where read and write operations start from) is advanced the number of bytes read.
Overrides:
readBytes in class File
Parameters:
bytes - the byte array to read data into
off - the offset position in the array
len - the number of bytes to read
Returns:
the number of bytes actually read or -1 if eof

skip

public void skip(int countBytes)
Skips countBytes bytes
Parameters:
countBytes - count of bytes ti skip