FileDocCategorySizeDatePackage
OSFileSystem.javaAPI DocAndroid 1.5 API8947Wed May 06 22:41:04 BST 2009org.apache.harmony.luni.platform

OSFileSystem

public class OSFileSystem extends OSComponent implements IFileSystem
This is the portable implementation of the file system interface.

Fields Summary
Constructors Summary
public OSFileSystem()

        super();
    
Methods Summary
public voidclose(int fileDescriptor)

        int rc = closeImpl(fileDescriptor);
        if (rc == -1) {
            throw new IOException();
        }
    
private native intcloseImpl(int fileDescriptor)

public voidfflush(int fileDescriptor, boolean metadata)

        int result = fflushImpl(fileDescriptor, metadata);
        if (result == -1) {
            throw new IOException();
        }
    
private native intfflushImpl(int fd, boolean metadata)

public native intgetAllocGranularity()
Returns the granularity for virtual memory allocation. Note that this value for Windows differs from the one for the page size (64K and 4K respectively).

public native intioctlAvailable(int fileDescriptor)

public booleanlock(int fileDescriptor, long start, long length, int type, boolean waitFlag)

        // Validate arguments
        validateLockArgs(type, start, length);
        int result = lockImpl(fileDescriptor, start, length, type, waitFlag);
        return result != -1;
    
private native intlockImpl(int fileDescriptor, long start, long length, int type, boolean wait)

public intopen(byte[] fileName, int mode)

        if (fileName == null) {
            throw new NullPointerException();
        }
        int handler = openImpl(fileName, mode);
        if (handler < 0) {
            throw new FileNotFoundException(new String(fileName));
        }
        return handler;
    
private native intopenImpl(byte[] fileName, int mode)

public longread(int fileDescriptor, byte[] bytes, int offset, int length)

        if (bytes == null) {
            throw new NullPointerException();
        }
        long bytesRead = readImpl(fileDescriptor, bytes, offset, length);
        if (bytesRead < -1) {
            throw new IOException();
        }
        return bytesRead;
    
public longreadDirect(int fileDescriptor, int address, int offset, int length)

        long bytesRead = readDirectImpl(fileDescriptor, address, offset, length);
        if (bytesRead < -1) {
            throw new IOException();
        }
        return bytesRead;
    
private native longreadDirectImpl(int fileDescriptor, int address, int offset, int length)

private native longreadImpl(int fileDescriptor, byte[] bytes, int offset, int length)

public longreadv(int fileDescriptor, int[] addresses, int[] offsets, int[] lengths, int size)

        long bytesRead = readvImpl(fileDescriptor, addresses, offsets, lengths,
                size);
        if (bytesRead < -1) {
            throw new IOException();
        }
        return bytesRead;
    
private native longreadvImpl(int fileDescriptor, int[] addresses, int[] offsets, int[] lengths, int size)

public longseek(int fileDescriptor, long offset, int whence)

        long pos = seekImpl(fileDescriptor, offset, whence);
        if (pos == -1) {
            throw new IOException();
        }
        return pos;
    
private native longseekImpl(int fd, long offset, int whence)

public longtransfer(int fileHandler, java.io.FileDescriptor socketDescriptor, long offset, long count)

        long result = transferImpl(fileHandler, socketDescriptor, offset, count);
        if (result < 0) throw new IOException();
        return result;
    
private native longtransferImpl(int fileHandler, java.io.FileDescriptor socketDescriptor, long offset, long count)

public voidtruncate(int fileDescriptor, long size)

        int rc = truncateImpl(fileDescriptor, size);
        if (rc < 0) {
            throw new IOException();
        }
    
private native inttruncateImpl(int fileDescriptor, long size)

public longttyRead(byte[] bytes, int offset, int length)

        long nChar = ttyReadImpl(bytes, offset, length);
        // BEGIN android-changed
        if (nChar < -1) {
            throw new IOException();
        }
        // END android-changed
        return nChar;
    
private native longttyReadImpl(byte[] bytes, int offset, int length)

public voidunlock(int fileDescriptor, long start, long length)

        // Validate arguments
        validateLockArgs(IFileSystem.SHARED_LOCK_TYPE, start, length);
        int result = unlockImpl(fileDescriptor, start, length);
        if (result == -1) {
            throw new IOException();
        }
    
private native intunlockImpl(int fileDescriptor, long start, long length)

private final voidvalidateLockArgs(int type, long start, long length)

        if ((type != IFileSystem.SHARED_LOCK_TYPE)
                && (type != IFileSystem.EXCLUSIVE_LOCK_TYPE)) {
            throw new IllegalArgumentException("Illegal lock type requested."); //$NON-NLS-1$
        }

        // Start position
        if (start < 0) {
            throw new IllegalArgumentException(
                    "Lock start position must be non-negative"); //$NON-NLS-1$
        }

        // Length of lock stretch
        if (length < 0) {
            throw new IllegalArgumentException(
                    "Lock length must be non-negative"); //$NON-NLS-1$
        }
    
public longwrite(int fileDescriptor, byte[] bytes, int offset, int length)

        long bytesWritten = writeImpl(fileDescriptor, bytes, offset, length);
        if (bytesWritten < 0) {
            throw new IOException();
        }
        return bytesWritten;
    
public longwriteDirect(int fileDescriptor, int address, int offset, int length)

        long bytesWritten = writeDirectImpl(fileDescriptor, address, offset,
                length);
        if (bytesWritten < 0) {
            throw new IOException();
        }
        return bytesWritten;
    
private native longwriteDirectImpl(int fileDescriptor, int address, int offset, int length)

private native longwriteImpl(int fileDescriptor, byte[] bytes, int offset, int length)

public longwritev(int fileDescriptor, int[] addresses, int[] offsets, int[] lengths, int size)

        long bytesWritten = writevImpl(fileDescriptor, addresses, offsets,
                lengths, size);
        if (bytesWritten < 0) {
            throw new IOException();
        }
        return bytesWritten;
    
private native longwritevImpl(int fileDescriptor, int[] addresses, int[] offsets, int[] lengths, int size)