當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。