當前位置: 首頁>>代碼示例>>Java>>正文


Java IFileSystem類代碼示例

本文整理匯總了Java中org.apache.harmony.luni.platform.IFileSystem的典型用法代碼示例。如果您正苦於以下問題:Java IFileSystem類的具體用法?Java IFileSystem怎麽用?Java IFileSystem使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IFileSystem類屬於org.apache.harmony.luni.platform包,在下文中一共展示了IFileSystem類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFileChannel

import org.apache.harmony.luni.platform.IFileSystem; //導入依賴的package包/類
public static FileChannel getFileChannel(Object stream, int fd, int mode) {
    switch (mode) {
        case IFileSystem.O_RDONLY:
            return new ReadOnlyFileChannel(stream, fd);
        case IFileSystem.O_WRONLY:
            return new WriteOnlyFileChannel(stream, fd);
        case IFileSystem.O_RDWR:
            return new ReadWriteFileChannel(stream, fd);
        case IFileSystem.O_RDWRSYNC:
            return new ReadWriteFileChannel(stream, fd);
        case IFileSystem.O_APPEND:
            return new WriteOnlyFileChannel(stream, fd, true);
        default:
            throw new RuntimeException("Unknown file channel type " + mode);
    }
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:17,代碼來源:FileChannelFactory.java

示例2: FileInputStream

import org.apache.harmony.luni.platform.IFileSystem; //導入依賴的package包/類
/**
 * Constructs a new {@code FileInputStream} based on {@code file}.
 *
 * @param file
 *            the file from which this stream reads.
 * @throws FileNotFoundException
 *             if {@code file} does not exist.
 * @throws SecurityException
 *             if a {@code SecurityManager} is installed and it denies the
 *             read request.
 */
public FileInputStream(File file) throws FileNotFoundException {
    super();
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        // For compatibility, nulls are passed to the manager.
        String filePath = (null == file ? null : file.getPath());
        security.checkRead(filePath);
    }
    if (file == null) {
        throw new NullPointerException("file == null");
    }
    fd = new FileDescriptor();
    fd.readOnly = true;
    fd.descriptor = fileSystem.open(file.getAbsolutePath(), IFileSystem.O_RDONLY);
    innerFD = true;
    // BEGIN android-removed
    // channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
    //         IFileSystem.O_RDONLY);
    // END android-removed
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:32,代碼來源:FileInputStream.java

示例3: skip

import org.apache.harmony.luni.platform.IFileSystem; //導入依賴的package包/類
/**
 * Skips {@code count} number of bytes in this stream. Subsequent
 * {@code read()}s will not return these bytes unless {@code reset()} is
 * used. If the underlying stream is unseekable, an IOException is thrown.
 *
 * @param count
 *            the number of bytes to skip.
 * @return the number of bytes actually skipped.
 * @throws IOException
 *             if {@code count < 0}, this stream is closed or unseekable,
 *             or another IOException occurs.
 */
@Override
public long skip(long count) throws IOException {
    openCheck();

    if (count == 0) {
        return 0;
    }
    if (count < 0) {
        throw new IOException("count < 0");
    }

    // The RI doesn't treat stdin as special. It throws IOException for
    // all non-seekable streams, so we do too. If you did want to support
    // non-seekable streams, the best way to do it would be to recognize
    // when lseek(2) fails with ESPIPE and call super.skip(count).
    synchronized (repositioningLock) {
        // Our seek returns the new offset, but we know it will throw an
        // exception if it couldn't perform exactly the seek we asked for.
        fileSystem.seek(fd.descriptor, count, IFileSystem.SEEK_CUR);
        return count;
    }
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:35,代碼來源:FileInputStream.java

示例4: basicLock

import org.apache.harmony.luni.platform.IFileSystem; //導入依賴的package包/類
protected FileLock basicLock(long position, long size, boolean shared,
        boolean wait) throws IOException {
    if (position < 0 || size < 0) {
        throw new IllegalArgumentException("Lock position and size must be non-negative");
    }
    int lockType = shared ? IFileSystem.SHARED_LOCK_TYPE : IFileSystem.EXCLUSIVE_LOCK_TYPE;
    FileLock pendingLock = new FileLockImpl(this, position, size, shared);
    lockManager.addLock(pendingLock);

    if (fileSystem.lock(handle, position, size, lockType, wait)) {
        return pendingLock;
    }

    // Lock acquisition failed
    lockManager.removeLock(pendingLock);
    return null;
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:18,代碼來源:FileChannelImpl.java

示例5: basicLock

import org.apache.harmony.luni.platform.IFileSystem; //導入依賴的package包/類
protected FileLock basicLock(long position, long size, boolean shared,
        boolean wait) throws IOException {
    if ((position < 0) || (size < 0)) {
        // nio.0A=Lock position and size must be non-negative.
        throw new IllegalArgumentException(Messages.getString("nio.0A")); //$NON-NLS-1$
    }
    int lockType = shared ? IFileSystem.SHARED_LOCK_TYPE
            : IFileSystem.EXCLUSIVE_LOCK_TYPE;
    FileLock pendingLock = new FileLockImpl(this, position, size, shared);
    lockManager.addLock(pendingLock);

    if (fileSystem.lock(handle, position, size, lockType, wait)) {
        return pendingLock;
    }

    // Lock acquisition failed
    lockManager.removeLock(pendingLock);
    return null;
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:20,代碼來源:FileChannelImpl.java

示例6: getFileChannel

import org.apache.harmony.luni.platform.IFileSystem; //導入依賴的package包/類
public static FileChannel getFileChannel(Object stream, long fd, int mode) {
    switch (mode) {
        case IFileSystem.O_RDONLY:
            return new ReadOnlyFileChannel(stream, fd);
        case IFileSystem.O_WRONLY:
            return new WriteOnlyFileChannel(stream, fd);
        case IFileSystem.O_RDWR:
            return new ReadWriteFileChannel(stream, fd);
        case IFileSystem.O_RDWRSYNC:
            return new ReadWriteFileChannel(stream, fd);
        case IFileSystem.O_APPEND:
            return new WriteOnlyFileChannel(stream, fd, true);
        default:
            // nio.09=Unknown file channel type: {0}
            throw new RuntimeException(Messages.getString("nio.09", mode)); //$NON-NLS-1$
    }
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:18,代碼來源:FileChannelFactory.java

示例7: FileInputStream

import org.apache.harmony.luni.platform.IFileSystem; //導入依賴的package包/類
/**
 * Constructs a new {@code FileInputStream} based on {@code file}.
 * 
 * @param file
 *            the file from which this stream reads.
 * @throws FileNotFoundException
 *             if {@code file} does not exist.
 * @throws SecurityException
 *             if a {@code SecurityManager} is installed and it denies the
 *             read request.
 */
public FileInputStream(File file) throws FileNotFoundException {
    super();
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        // For compatibility, nulls are passed to the manager.
        String filePath = (null == file ? null : file.getPath());
        security.checkRead(filePath);
    }
    if (file == null) {
        // luni.4D=Argument must not be null
        throw new NullPointerException(Messages.getString("luni.4D")); //$NON-NLS-1$
    }
    fd = new FileDescriptor();
    fd.readOnly = true;
    fd.descriptor = fileSystem.open(file.properPath(true),
            IFileSystem.O_RDONLY);
    innerFD = true;
    channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
            IFileSystem.O_RDONLY);
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:32,代碼來源:FileInputStream.java

示例8: setLength

import org.apache.harmony.luni.platform.IFileSystem; //導入依賴的package包/類
/**
 * Sets the length of this file to {@code newLength}. If the current file is
 * smaller, it is expanded but the contents from the previous end of the
 * file to the new end are undefined. The file is truncated if its current
 * size is bigger than {@code newLength}. If the current file pointer
 * position is in the truncated part, it is set to the end of the file.
 * 
 * @param newLength
 *            the new file length in bytes.
 * @throws IllegalArgumentException
 *             if {@code newLength < 0}.
 * @throws IOException
 *             if this file is closed or another I/O error occurs.
 */
public void setLength(long newLength) throws IOException {
    openCheck();
    if (newLength < 0) {
        throw new IllegalArgumentException();
    }
    synchronized (repositionLock) {
        long position = fileSystem.seek(fd.descriptor, 0,
                IFileSystem.SEEK_CUR);
        fileSystem.truncate(fd.descriptor, newLength);
        seek(position > newLength ? newLength : position);
    }

    // if we are in "rws" mode, attempt to sync file+metadata
    if (syncMetadata) {
        fd.sync();
    }
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:32,代碼來源:RandomAccessFile.java

示例9: basicLock

import org.apache.harmony.luni.platform.IFileSystem; //導入依賴的package包/類
protected FileLock basicLock(long position, long size, boolean shared,
		boolean wait) throws IOException {
	if ((position < 0) || (size < 0)) {
           // nio.0A=Lock position and size must be non-negative.
		throw new IllegalArgumentException(
				Messages.getString("nio.0A"));  //$NON-NLS-1$
	}
       int lockType = shared ? IFileSystem.SHARED_LOCK_TYPE
               : IFileSystem.EXCLUSIVE_LOCK_TYPE;
	FileLock pendingLock = new FileLockImpl(this, position, size, shared);
	lockManager.addLock(pendingLock);

	if (fileSystem.lock(handle, position, size, lockType, wait)) {
		return pendingLock;
	}

	// Lock acquisition failed
	lockManager.removeLock(pendingLock);
	return null;
}
 
開發者ID:freeVM,項目名稱:freeVM,代碼行數:21,代碼來源:FileChannelImpl.java

示例10: getFileChannel

import org.apache.harmony.luni.platform.IFileSystem; //導入依賴的package包/類
public static FileChannel getFileChannel(Object stream, long fd, int mode) {
       switch(mode){
       case IFileSystem.O_RDONLY:
           return new ReadOnlyFileChannel(stream, fd);
       case IFileSystem.O_WRONLY:
           return new WriteOnlyFileChannel(stream, fd);
       case IFileSystem.O_RDWR:
           return new ReadWriteFileChannel(stream, fd);
       case IFileSystem.O_RDWRSYNC:
           return new ReadWriteFileChannel(stream, fd);
       case IFileSystem.O_APPEND:
           return new WriteOnlyFileChannel(stream, fd, true);
       default:
           // nio.09=Unknown file channel type: {0}
           throw new RuntimeException(Messages.getString("nio.09", mode));  //$NON-NLS-1$
       }
}
 
開發者ID:freeVM,項目名稱:freeVM,代碼行數:18,代碼來源:FileChannelFactory.java

示例11: FileInputStream

import org.apache.harmony.luni.platform.IFileSystem; //導入依賴的package包/類
/**
 * Constructs a new FileInputStream on the File <code>file</code>. If the
 * file does not exist, the <code>FileNotFoundException</code> is thrown.
 * 
 * @param file
 *            the File on which to stream reads.
 * 
 * @throws FileNotFoundException
 *             If the <code>file</code> is not found.
 * 
 * @see java.lang.SecurityManager#checkRead(FileDescriptor)
 * @see java.lang.SecurityManager#checkRead(String)
 * @see java.lang.SecurityManager#checkRead(String, Object)
 */
public FileInputStream(File file) throws FileNotFoundException {
    super();
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        String filePath = (null == file ? null : file.getPath());
        security.checkRead(filePath);
    }
    fd = new FileDescriptor();
    fd.readOnly = true;
    fd.descriptor = fileSystem.open(file.properPath(true),
            IFileSystem.O_RDONLY);
    innerFD = true;
    channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
            IFileSystem.O_RDONLY);
}
 
開發者ID:freeVM,項目名稱:freeVM,代碼行數:30,代碼來源:FileInputStream.java

示例12: available

import org.apache.harmony.luni.platform.IFileSystem; //導入依賴的package包/類
/**
 * Answers a int representing then number of bytes that are available before
 * this InputStream will block. This method always returns the size of the
 * file minus the current position.
 * 
 * @return the number of bytes available before blocking.
 * 
 * @throws IOException
 *             If an error occurs in this stream.
 */
@Override
public int available() throws IOException {
    openCheck();
    synchronized (repositioningLock) {
        // stdin requires special handling
        if (fd == FileDescriptor.in) {
            return (int) fileSystem.ttyAvailable();
        }

        long currentPosition = fileSystem.seek(fd.descriptor, 0L,
                IFileSystem.SEEK_CUR);
        long endOfFilePosition = fileSystem.seek(fd.descriptor, 0L,
                IFileSystem.SEEK_END);
        fileSystem.seek(fd.descriptor, currentPosition,
                IFileSystem.SEEK_SET);
        return (int) (endOfFilePosition - currentPosition);
    }
}
 
開發者ID:freeVM,項目名稱:freeVM,代碼行數:29,代碼來源:FileInputStream.java

示例13: setLength

import org.apache.harmony.luni.platform.IFileSystem; //導入依賴的package包/類
/**
 * Set the length of this file to be <code>newLength</code>. If the
 * current file is smaller, it will be expanded and the filePosition will be
 * set to the new file length. If the <code>newLength</code> is smaller
 * then the file will be truncated.
 * 
 * @param newLength
 *            the desired file length
 * 
 * @throws IOException
 *             If the stream is already closed or another IOException
 *             occurs.
 */
public void setLength(long newLength) throws IOException {
    openCheck();
    if (newLength < 0) {
        throw new IllegalArgumentException();
    }
    synchronized (repositionLock) {
        long position = fileSystem.seek(fd.descriptor, 0,
                IFileSystem.SEEK_CUR);
        fileSystem.truncate(fd.descriptor, newLength);
        seek(position > newLength ? newLength : position);
    }

    // if we are in "rws" mode, attempt to sync file+metadata
    if (syncMetadata) {
        fd.sync();
    }
}
 
開發者ID:freeVM,項目名稱:freeVM,代碼行數:31,代碼來源:RandomAccessFile.java

示例14: FileInputStream

import org.apache.harmony.luni.platform.IFileSystem; //導入依賴的package包/類
/**
 * Constructs a new {@code FileInputStream} based on {@code file}.
 * 
 * @param file
 *            the file from which this stream reads.
 * @throws FileNotFoundException
 *             if {@code file} does not exist.
 * @throws SecurityException
 *             if a {@code SecurityManager} is installed and it denies the
 *             read request.
 */
public FileInputStream(File file) throws FileNotFoundException {
    super();
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        // For compatibility, nulls are passed to the manager.
        String filePath = (null == file ? null : file.getPath());
        security.checkRead(filePath);
    }
    if (file == null) {
        // luni.4D=Argument must not be null
        throw new NullPointerException(Messages.getString("luni.4D")); //$NON-NLS-1$
    }
    fd = new FileDescriptor();
    fd.readOnly = true;
    fd.descriptor = fileSystem.open(file.properPath(true),
            IFileSystem.O_RDONLY);
    channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
            IFileSystem.O_RDONLY);
}
 
開發者ID:freeVM,項目名稱:freeVM,代碼行數:31,代碼來源:FileInputStream.java

示例15: getChannel

import org.apache.harmony.luni.platform.IFileSystem; //導入依賴的package包/類
/**
 * Returns the {@link FileChannel} equivalent to this input stream.
 * <p>
 * The file channel is read-only and has an initial position within the file
 * that is the same as the current position of this stream within the file.
 * All changes made to the underlying file descriptor state via the channel
 * are visible by the input stream and vice versa.
 *
 * @return the file channel for this stream.
 */
public FileChannel getChannel() {
    // BEGIN android-changed
    synchronized(this) {
        if (channel == null) {
            channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
                    IFileSystem.O_RDONLY);
        }
        return channel;
    }
    // END android-changed
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:22,代碼來源:FileInputStream.java


注:本文中的org.apache.harmony.luni.platform.IFileSystem類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。