当前位置: 首页>>代码示例>>Java>>正文


Java FileChannelImpl类代码示例

本文整理汇总了Java中sun.nio.ch.FileChannelImpl的典型用法代码示例。如果您正苦于以下问题:Java FileChannelImpl类的具体用法?Java FileChannelImpl怎么用?Java FileChannelImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FileChannelImpl类属于sun.nio.ch包,在下文中一共展示了FileChannelImpl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newFileChannel

import sun.nio.ch.FileChannelImpl; //导入依赖的package包/类
/**
 * Open/creates file, returning FileChannel to access the file
 *
 * @param   pathForWindows
 *          The path of the file to open/create
 * @param   pathToCheck
 *          The path used for permission checks (if security manager)
 */
static FileChannel newFileChannel(String pathForWindows,
                                  String pathToCheck,
                                  Set<? extends OpenOption> options,
                                  long pSecurityDescriptor)
    throws WindowsException
{
    Flags flags = Flags.toFlags(options);

    // default is reading; append => writing
    if (!flags.read && !flags.write) {
        if (flags.append) {
            flags.write = true;
        } else {
            flags.read = true;
        }
    }

    // validation
    if (flags.read && flags.append)
        throw new IllegalArgumentException("READ + APPEND not allowed");
    if (flags.append && flags.truncateExisting)
        throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed");

    FileDescriptor fdObj = open(pathForWindows, pathToCheck, flags, pSecurityDescriptor);
    return FileChannelImpl.open(fdObj, pathForWindows, flags.read, flags.write, flags.append, null);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:35,代码来源:WindowsChannelFactory.java

示例2: map

import sun.nio.ch.FileChannelImpl; //导入依赖的package包/类
/**
 * Creates a mapping of the file on disk starting at file position and of size length to pages in OS.
 * May throw OutOfMemory error if you have exhausted memory. Force garbage collection and
 * re-attempt.
 * @param fileChannel the FileChannel
 * @param position the offset in bytes into the file
 * @param lengthBytes the length in bytes
 * @return the native base offset address
 * @throws RuntimeException Encountered an exception while mapping
 */
static final long map(final FileChannel fileChannel, final long position, final long lengthBytes)
        throws RuntimeException {
  final int pagePosition = (int) (position % unsafe.pageSize());
  final long mapPosition = position - pagePosition;
  final long mapSize = lengthBytes + pagePosition;

  try {
    final Method method =
            FileChannelImpl.class.getDeclaredMethod("map0", int.class, long.class, long.class);
    method.setAccessible(true);
    final long nativeBaseOffset = (long) method.invoke(fileChannel, 1, mapPosition, mapSize);
    return nativeBaseOffset;
  } catch (final Exception e) {
    throw new RuntimeException(
            String.format("Encountered %s exception while mapping", e.getClass()));
  }
}
 
开发者ID:DataSketches,项目名称:memory,代码行数:28,代码来源:AllocateDirectMap.java

示例3: getChannel

import sun.nio.ch.FileChannelImpl; //导入依赖的package包/类
/**
 * Returns the unique {@link java.nio.channels.FileChannel FileChannel}
 * object associated with this file input stream.
 *
 * <p> The initial {@link java.nio.channels.FileChannel#position()
 * position} of the returned channel will be equal to the
 * number of bytes read from the file so far.  Reading bytes from this
 * stream will increment the channel's position.  Changing the channel's
 * position, either explicitly or by reading, will change this stream's
 * file position.
 *
 * @return  the file channel associated with this file input stream
 *
 * @since 1.4
 * @spec JSR-51
 */
public FileChannel getChannel() {
    FileChannel fc = this.channel;
    if (fc == null) {
        synchronized (this) {
            fc = this.channel;
            if (fc == null) {
                this.channel = fc = FileChannelImpl.open(fd, path, true, false, this);
                if (closed) {
                    try {
                        // possible race with close(), benign since
                        // FileChannel.close is final and idempotent
                        fc.close();
                    } catch (IOException ioe) {
                        throw new InternalError(ioe); // should not happen
                    }
                }
            }
        }
    }
    return fc;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:FileInputStream.java

示例4: getChannel

import sun.nio.ch.FileChannelImpl; //导入依赖的package包/类
/**
 * Returns the unique {@link java.nio.channels.FileChannel FileChannel}
 * object associated with this file.
 *
 * <p> The {@link java.nio.channels.FileChannel#position()
 * position} of the returned channel will always be equal to
 * this object's file-pointer offset as returned by the {@link
 * #getFilePointer getFilePointer} method.  Changing this object's
 * file-pointer offset, whether explicitly or by reading or writing bytes,
 * will change the position of the channel, and vice versa.  Changing the
 * file's length via this object will change the length seen via the file
 * channel, and vice versa.
 *
 * @return  the file channel associated with this file
 *
 * @since 1.4
 * @spec JSR-51
 */
public final FileChannel getChannel() {
    FileChannel fc = this.channel;
    if (fc == null) {
        synchronized (this) {
            fc = this.channel;
            if (fc == null) {
                this.channel = fc = FileChannelImpl.open(fd, path, true, rw, this);
                if (closed.get()) {
                    try {
                        fc.close();
                    } catch (IOException ioe) {
                        throw new InternalError(ioe); // should not happen
                    }
                }
            }
        }
    }
    return fc;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:RandomAccessFile.java

示例5: getChannel

import sun.nio.ch.FileChannelImpl; //导入依赖的package包/类
/**
 * Returns the unique {@link java.nio.channels.FileChannel FileChannel}
 * object associated with this file output stream.
 *
 * <p> The initial {@link java.nio.channels.FileChannel#position()
 * position} of the returned channel will be equal to the
 * number of bytes written to the file so far unless this stream is in
 * append mode, in which case it will be equal to the size of the file.
 * Writing bytes to this stream will increment the channel's position
 * accordingly.  Changing the channel's position, either explicitly or by
 * writing, will change this stream's file position.
 *
 * @return  the file channel associated with this file output stream
 *
 * @since 1.4
 * @spec JSR-51
 */
public FileChannel getChannel() {
    FileChannel fc = this.channel;
    if (fc == null) {
        synchronized (this) {
            fc = this.channel;
            if (fc == null) {
                this.channel = fc = FileChannelImpl.open(fd, path, false, true, this);
                if (closed) {
                    try {
                        // possible race with close(), benign since
                        // FileChannel.close is final and idempotent
                        fc.close();
                    } catch (IOException ioe) {
                        throw new InternalError(ioe); // should not happen
                    }
                }
            }
        }
    }
    return fc;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:FileOutputStream.java

示例6: getChannel

import sun.nio.ch.FileChannelImpl; //导入依赖的package包/类
/**
 * Returns the unique {@link java.nio.channels.FileChannel FileChannel}
 * object associated with this file input stream.
 *
 * <p> The initial {@link java.nio.channels.FileChannel#position()
 * position} of the returned channel will be equal to the
 * number of bytes read from the file so far.  Reading bytes from this
 * stream will increment the channel's position.  Changing the channel's
 * position, either explicitly or by reading, will change this stream's
 * file position.
 *
 * @return  the file channel associated with this file input stream
 *
 * @since 1.4
 * @spec JSR-51
 */
public FileChannel getChannel() {
    FileChannel fc = this.channel;
    if (fc == null) {
        synchronized (this) {
            fc = this.channel;
            if (fc == null) {
                this.channel = fc = FileChannelImpl.open(fd, path, true, false, this);
                if (closed.get()) {
                    try {
                        fc.close();
                    } catch (IOException ioe) {
                        throw new InternalError(ioe); // should not happen
                    }
                }
            }
        }
    }
    return fc;
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:36,代码来源:FileInputStream.java

示例7: getChannel

import sun.nio.ch.FileChannelImpl; //导入依赖的package包/类
/**
 * Returns the unique {@link java.nio.channels.FileChannel FileChannel}
 * object associated with this file output stream.
 *
 * <p> The initial {@link java.nio.channels.FileChannel#position()
 * position} of the returned channel will be equal to the
 * number of bytes written to the file so far unless this stream is in
 * append mode, in which case it will be equal to the size of the file.
 * Writing bytes to this stream will increment the channel's position
 * accordingly.  Changing the channel's position, either explicitly or by
 * writing, will change this stream's file position.
 *
 * @return  the file channel associated with this file output stream
 *
 * @since 1.4
 * @spec JSR-51
 */
public FileChannel getChannel() {
    FileChannel fc = this.channel;
    if (fc == null) {
        synchronized (this) {
            fc = this.channel;
            if (fc == null) {
                this.channel = fc = FileChannelImpl.open(fd, path, false, true, this);
                if (closed.get()) {
                    try {
                        fc.close();
                    } catch (IOException ioe) {
                        throw new InternalError(ioe); // should not happen
                    }
                }
            }
        }
    }
    return fc;
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:37,代码来源:FileOutputStream.java

示例8: getChannel

import sun.nio.ch.FileChannelImpl; //导入依赖的package包/类
/**
 * Returns the unique {@link java.nio.channels.FileChannel FileChannel}
 * object associated with this file.
 *
 * <p> The {@link java.nio.channels.FileChannel#position()
 * </code>position<code>} of the returned channel will always be equal to
 * this object's file-pointer offset as returned by the {@link
 * #getFilePointer getFilePointer} method.  Changing this object's
 * file-pointer offset, whether explicitly or by reading or writing bytes,
 * will change the position of the channel, and vice versa.  Changing the
 * file's length via this object will change the length seen via the file
 * channel, and vice versa.
 *
 * @return  the file channel associated with this file
 *
 * @since 1.4
 * @spec JSR-51
 */
public final FileChannel getChannel() {
    synchronized (this) {
        if (channel == null) {
            channel = FileChannelImpl.open(fd, path, true, rw, this);

            /*
             * FileDescriptor could be shared by FileInputStream or
             * FileOutputStream.
             * Ensure that FD is GC'ed only when all the streams/channels
             * are done using it.
             * Increment fd's use count. Invoking the channel's close()
             * method will result in decrementing the use count set for
             * the channel.
             */
            fd.incrementAndGetUseCount();
        }
        return channel;
    }
}
 
开发者ID:ZhaoX,项目名称:jdk-1.7-annotated,代码行数:38,代码来源:RandomAccessFile.java

示例9: getChannel

import sun.nio.ch.FileChannelImpl; //导入依赖的package包/类
/**
 * Returns the unique {@link java.nio.channels.FileChannel FileChannel}
 * object associated with this file.
 *
 * <p> The {@link java.nio.channels.FileChannel#position()
 * </code>position<code>} of the returned channel will always be equal to
 * this object's file-pointer offset as returned by the {@link
 * #getFilePointer getFilePointer} method.  Changing this object's
 * file-pointer offset, whether explicitly or by reading or writing bytes,
 * will change the position of the channel, and vice versa.  Changing the
 * file's length via this object will change the length seen via the file
 * channel, and vice versa.
 *
 * @return  the file channel associated with this file
 *
 * @since 1.4
 * @spec JSR-51
 */
public final FileChannel getChannel() {
    synchronized (this) {
        if (channel == null) {
            channel = FileChannelImpl.open(fd, true, rw, this);

            /*
             * FileDescriptor could be shared by FileInputStream or
             * FileOutputStream.
             * Ensure that FD is GC'ed only when all the streams/channels
             * are done using it.
             * Increment fd's use count. Invoking the channel's close()
             * method will result in decrementing the use count set for
             * the channel.
             */
            fd.incrementAndGetUseCount();
        }
        return channel;
    }
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:38,代码来源:RandomAccessFile.java

示例10: newFileChannel

import sun.nio.ch.FileChannelImpl; //导入依赖的package包/类
/**
 * Constructs a file channel by opening a file using a dfd/path pair
 */
static FileChannel newFileChannel(int dfd,
                                  UnixPath path,
                                  String pathForPermissionCheck,
                                  Set<? extends OpenOption> options,
                                  int mode)
    throws UnixException
{
    Flags flags = Flags.toFlags(options);

    // default is reading; append => writing
    if (!flags.read && !flags.write) {
        if (flags.append) {
            flags.write = true;
        } else {
            flags.read = true;
        }
    }

    // validation
    if (flags.read && flags.append)
        throw new IllegalArgumentException("READ + APPEND not allowed");
    if (flags.append && flags.truncateExisting)
        throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed");

    FileDescriptor fdObj = open(dfd, path, pathForPermissionCheck, flags, mode);
    return FileChannelImpl.open(fdObj, path.toString(), flags.read, flags.write, flags.append, null);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:UnixChannelFactory.java

示例11: unmap

import sun.nio.ch.FileChannelImpl; //导入依赖的package包/类
/**
 * Removes existing mapping
 */
private void unmap() throws RuntimeException {
  try {
    final Method method = FileChannelImpl.class.getDeclaredMethod("unmap0", long.class, long.class);
    method.setAccessible(true);
    method.invoke(myFc, actualNativeBaseOffset, myCapacity);
    myRaf.close();
  } catch (final Exception e) {
    throw new RuntimeException(
            String.format("Encountered %s exception while freeing memory", e.getClass()));
  }
}
 
开发者ID:DataSketches,项目名称:memory,代码行数:15,代码来源:AllocateDirectMap.java

示例12: newFileChannel

import sun.nio.ch.FileChannelImpl; //导入依赖的package包/类
/**
 * Constructs a file channel by opening a file using a dfd/path pair
 */
static FileChannel newFileChannel(int dfd,
                                  UnixPath path,
                                  String pathForPermissionCheck,
                                  Set<? extends OpenOption> options,
                                  int mode)
    throws UnixException
{
    Flags flags = Flags.toFlags(options);

    // default is reading; append => writing
    if (!flags.read && !flags.write) {
        if (flags.append) {
            flags.write = true;
        } else {
            flags.read = true;
        }
    }

    // validation
    if (flags.read && flags.append)
        throw new IllegalArgumentException("READ + APPEND not allowed");
    if (flags.append && flags.truncateExisting)
        throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed");

    FileDescriptor fdObj = open(dfd, path, pathForPermissionCheck, flags, mode);
    return FileChannelImpl.open(fdObj, path.toString(), flags.read, flags.write, null);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:UnixChannelFactory.java

示例13: newFileChannel

import sun.nio.ch.FileChannelImpl; //导入依赖的package包/类
/**
 * Open/creates file, returning FileChannel to access the file
 *
 * @param   pathForWindows
 *          The path of the file to open/create
 * @param   pathToCheck
 *          The path used for permission checks (if security manager)
 */
static FileChannel newFileChannel(String pathForWindows,
                                  String pathToCheck,
                                  Set<? extends OpenOption> options,
                                  long pSecurityDescriptor)
    throws WindowsException
{
    Flags flags = Flags.toFlags(options);

    // default is reading; append => writing
    if (!flags.read && !flags.write) {
        if (flags.append) {
            flags.write = true;
        } else {
            flags.read = true;
        }
    }

    // validation
    if (flags.read && flags.append)
        throw new IllegalArgumentException("READ + APPEND not allowed");
    if (flags.append && flags.truncateExisting)
        throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed");

    FileDescriptor fdObj = open(pathForWindows, pathToCheck, flags, pSecurityDescriptor);
    return FileChannelImpl.open(fdObj, pathForWindows, flags.read, flags.write, null);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:WindowsChannelFactory.java

示例14: initRegionSizeGranularity

import sun.nio.ch.FileChannelImpl; //导入依赖的package包/类
private static long initRegionSizeGranularity() {
    try {
        return (Long)getMethod(FileChannelImpl.class, "initIDs").invoke(null);
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:terzerm,项目名称:fx-highway,代码行数:8,代码来源:MappedRegion.java

示例15: getChannel

import sun.nio.ch.FileChannelImpl; //导入依赖的package包/类
public FileChannel getChannel(){
    synchronized (this){
        if (channel == null){
            channel = FileChannelImpl.open(fd, path, true, false, this);
        }
        
        return channel;
    }
}
 
开发者ID:cFerg,项目名称:MineJava,代码行数:10,代码来源:FileInputStream.java


注:本文中的sun.nio.ch.FileChannelImpl类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。