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


Java FileChannel.isOpen方法代码示例

本文整理汇总了Java中java.nio.channels.FileChannel.isOpen方法的典型用法代码示例。如果您正苦于以下问题:Java FileChannel.isOpen方法的具体用法?Java FileChannel.isOpen怎么用?Java FileChannel.isOpen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.channels.FileChannel的用法示例。


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

示例1: flush

import java.nio.channels.FileChannel; //导入方法依赖的package包/类
public void flush() {
    if (!needsFlush) {
        return;
    }
    needsFlush = false;
    LOGGER.info("flushing bucket {}", bucketNumber);
    try {
        synchronized (this) {
            final FileChannel openChannel = getOpenChannel();
            if (openChannel.isOpen()) {
                openChannel.force(wantsTimestampUpdate);
                if (!wantsTimestampUpdate) {
                    Files.setLastModifiedTime(filePath, lastModifiedTime);
                } else {
                    lastModifiedTime = FileTime.from(Instant.now());
                }
                wantsTimestampUpdate = false;
            }
        }
    } catch (IOException e) {
        LOGGER.warn("unable to flush file of bucket {}", bucketNumber);
    }
}
 
开发者ID:MineboxOS,项目名称:minebox,代码行数:24,代码来源:SingleFileBucket.java

示例2: write

import java.nio.channels.FileChannel; //导入方法依赖的package包/类
/**
 * Dispose of a ByteBuffer which has been acquired for writing by one of
 * the write methods, writing its contents to the file.
 */
public int write (ByteBuffer bb) throws IOException {
    synchronized (this) {
        if (bb == buffer) {
            buffer = null;
        }
    }
    int position = size();
    int byteCount = bb.position();
    bb.flip();
    FileChannel channel = writeChannel();
    if (channel.isOpen()) { //If a thread was terminated while writing, it will be closed
        Thread.interrupted(); // #186629: must clear interrupt flag or channel will be broken
        channel.write (bb);
        synchronized (this) {
            bytesWritten += byteCount;
            outstandingBufferCount--;
        }
    }
    return position;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:FileMapStorage.java

示例3: transfer

import java.nio.channels.FileChannel; //导入方法依赖的package包/类
static public long transfer(long position, long count, FileInputStream src, FileOutputStream dst) throws IOException {
    FileChannel srcChannel = src.getChannel();
    FileChannel dstChannel = dst.getChannel();
    if (!srcChannel.isOpen()) {
        throw new ClosedChannelException();
    }
    if (!dstChannel.isOpen()) {
        throw new ClosedChannelException();
    }

    if (position < 0 || count < 0) {
        throw new IllegalArgumentException("position=" + position + " count=" + count);
    }

    if (count == 0 || position >= srcChannel.size()) {
        return 0;
    }
    count = Math.min(count, srcChannel.size() - position);

    FileDescriptor inFd = src.getFD();
    FileDescriptor outFd = dst.getFD();
    long rc = 0;
    rc = native_sendfile_64(outFd, inFd, position, count);
    return rc;
}
 
开发者ID:archos-sa,项目名称:aos-FileCoreLibrary,代码行数:26,代码来源:ArchosFileChannel.java

示例4: copiarArquivo

import java.nio.channels.FileChannel; //导入方法依赖的package包/类
public void copiarArquivo(File source, File destination) throws IOException {
    if (destination.exists()) {
        destination.delete();
    }
    FileChannel sourceChannel = null;
    FileChannel destinationChannel = null;
    try {
        sourceChannel = new FileInputStream(source).getChannel();
        destinationChannel = new FileOutputStream(destination).getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(),
                destinationChannel);
    } finally {
        if (sourceChannel != null && sourceChannel.isOpen()) {
            sourceChannel.close();
        }
        if (destinationChannel != null && destinationChannel.isOpen()) {
            destinationChannel.close();
        }
    }
}
 
开发者ID:wesleyreis1808,项目名称:projetomcdonalds,代码行数:21,代码来源:ControlerInicial.java

示例5: force

import java.nio.channels.FileChannel; //导入方法依赖的package包/类
public static void force(FileChannel fc, boolean metaData) throws IOException
{
    Preconditions.checkNotNull(fc);
    if (SKIP_SYNC)
    {
        if (!fc.isOpen())
            throw new ClosedChannelException();
    }
    else
    {
        fc.force(metaData);
    }
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:14,代码来源:SyncUtil.java

示例6: close

import java.nio.channels.FileChannel; //导入方法依赖的package包/类
public void close() throws IOException {
    LOGGER.debug("closing bucket {} ", bucketNumber);
    final FileChannel openChannel = getOpenChannel();
    if (openChannel.isOpen()) {
        flush();
        openChannel.close();
    } else {
        LOGGER.warn("closing bucket {} without an open channel.", bucketNumber);
    }
    randomAccessFile.close();
}
 
开发者ID:MineboxOS,项目名称:minebox,代码行数:12,代码来源:SingleFileBucket.java

示例7: AsyncFileLock

import java.nio.channels.FileChannel; //导入方法依赖的package包/类
/**
 * Creates a new AsyncFileLock from the given FileChannel.
 * The channel must have been opened with the WRITE option.
 * @param file to lock.
 * @throws IOException I/O error happened.
 */
public AsyncFileLock(FileChannel file) throws IOException
{
   Objects.requireNonNull(file);
   if (!file.isOpen())
   {
      throw new IllegalArgumentException("param `file` is closed");
   }
   fileToLock = file;
   closeChannel = false;
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:17,代码来源:AsyncFileLock.java

示例8: copiarArquivos

import java.nio.channels.FileChannel; //导入方法依赖的package包/类
/**
 * Cria a cópia de um arquivo para o local passado como parâmetro
 *
 * @param origem caminho completo do arquivo a ser copiado
 * @param destino caminho completo (com nome e extensão) do local de
 * gravação
 * @return {@code true} ou {@code false}
 * @throws java.io.IOException
 *
 */
public static boolean copiarArquivos(File origem, File destino) throws IOException {
    if (destino.exists()) {
        destino.delete();
    }
    FileChannel sourceChannel = null;
    FileChannel destinationChannel = null;

    try {
        sourceChannel = new FileInputStream(origem).getChannel();
        destinationChannel = new FileOutputStream(destino).getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(),
                destinationChannel);
    } catch (IOException ioe) {
        return false;
    } finally {
        if (sourceChannel != null && sourceChannel.isOpen()) {
            sourceChannel.close();
        }
        if (destinationChannel != null && destinationChannel.isOpen()) {
            destinationChannel.close();
        }
    }
    return true;
}
 
开发者ID:limagiran,项目名称:hearthstone,代码行数:35,代码来源:Dir.java

示例9: writeChannel

import java.nio.channels.FileChannel; //导入方法依赖的package包/类
private FileChannel writeChannel() throws IOException {
    FileChannel channel = fileChannel();
    closed = !channel.isOpen();
    return channel;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:6,代码来源:FileMapStorage.java

示例10: read

import java.nio.channels.FileChannel; //导入方法依赖的package包/类
public void
read(
	RandomAccessFile	raf,
	DirectByteBuffer	buffer,
	long				offset )

	throws FMFileManagerException
{
	if (raf == null){

		throw new FMFileManagerException( "read: raf is null" );
	}

	FileChannel fc = raf.getChannel();

	if ( !fc.isOpen()){

		Debug.out("FileChannel is closed: " + owner.getName());

		throw( new FMFileManagerException( "read - file is closed"));
	}

	AEThread2.setDebug( owner );

	try{
		if(USE_MMAP)
		{
			long remainingInFile = fc.size()-offset;
			long remainingInTargetBuffer = buffer.remaining(DirectByteBuffer.SS_FILE);
			MappedByteBuffer buf = fc.map(MapMode.READ_ONLY, offset, Math.min(remainingInFile,remainingInTargetBuffer));
			buffer.put(DirectByteBuffer.SS_FILE, buf);
		} else {
			fc.position(offset);
			while (fc.position() < fc.size() && buffer.hasRemaining(DirectByteBuffer.SS_FILE))
				buffer.read(DirectByteBuffer.SS_FILE,fc);
		}



	}catch ( Exception e ){

		Debug.printStackTrace( e );

		throw( new FMFileManagerException( "read fails", e ));
	}
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:47,代码来源:FMFileAccessLinear.java


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