/** * Returns if channel is open. * * @return Returns if channel is open. */ public boolean isOpened() { return (fileChannel != null) && fileChannel.isOpen(); }
/** * @return {@code true} */ public boolean exists() { return readCh != null && readCh.isOpen(); }
@Override public boolean isOpen() { return ac.isOpen(); }
@Override public final boolean isOpen() { return ac.isOpen(); }
@Override public boolean isOpen() { return chan.isOpen(); }
public AsynchronousFileChannel getAsyncChannel() { if (asyncChannel != null) { if (asyncChannel.isOpen()) return asyncChannel; } synchronized (this) { if (asyncChannel != null) { // check again while synchronized if (asyncChannel.isOpen()) return asyncChannel; } try { asyncChannel = AsynchronousFileChannel.open(path, StandardOpenOption.READ); } catch (IOException e) { throw new RuntimeException(e); } asyncChannelOpenCount++; return asyncChannel; } }
public AsynchronousFileChannel getAsyncChannel() { if (asyncChannel != null) { if (asyncChannel.isOpen()) return asyncChannel; } synchronized (this) { if (asyncChannel != null) { // check again while synchronized if (asyncChannel.isOpen()) return asyncChannel; } try { asyncChannel = AsynchronousFileChannel.open(path, StandardOpenOption.READ); } catch (IOException e) { throw new RuntimeException(e); } asyncChannelOpenCount++; return asyncChannel; } }
@Override public void postStop() { try { if (channel.isOpen()) channel.close(); } catch (Exception ex) { // Remove when #21168 is fixed throw new RuntimeException(ex); } } };
@Override public AsynchronousFileChannel getAsyncChannel() { if (asyncChannel != null) { if (asyncChannel.isOpen()) return asyncChannel; } synchronized(this) { if (asyncChannel != null) { // check again while synchronized if (asyncChannel.isOpen()) return asyncChannel; } try { if(readOnly) { asyncChannel = AsynchronousFileChannel.open(path, StandardOpenOption.READ); } else { asyncChannel = AsynchronousFileChannel.open(path, StandardOpenOption.READ, StandardOpenOption.WRITE); } } catch (IOException e) { throw new RuntimeException(e); } asyncChannelOpenCount++; return asyncChannel; } }
public void close() { _log.debug("closing file: " + file.getAbsolutePath()); // prevent further write operations this.closeAfterWrite = true; // wait for the on-going writes to end while (this.writeCount.get() != 0) { try { Thread.sleep(10); } catch (InterruptedException e) { } } // close the file if (this.ch.isOpen()) { try { this.ch.close(); } catch (IOException e) { } } } }
@Override public AsynchronousFileChannel getAsyncChannel() { if (asyncChannel != null) { if (asyncChannel.isOpen()) return asyncChannel; } synchronized(this) { if (asyncChannel != null) { // check again while synchronized if (asyncChannel.isOpen()) return asyncChannel; } try { if(readOnly) { asyncChannel = AsynchronousFileChannel.open(path, StandardOpenOption.READ); } else { asyncChannel = AsynchronousFileChannel.open(path, StandardOpenOption.READ, StandardOpenOption.WRITE); } } catch (IOException e) { throw new RuntimeException(e); } asyncChannelOpenCount++; return asyncChannel; } }
private void readData() { if (!inputChannel.isOpen()) { return;
public ChunkReader(Input fileInput, Path path, AsynchronousFileChannel fileChannel, BlockingQueue<FileChunk> chunks, int initialChunkSize, FileInput.InitialReadPosition initialReadPosition, ChunkReaderScheduler chunkReaderScheduler) { this.fileInput = fileInput; this.path = path; this.fileChannel = fileChannel; this.chunks = chunks; this.initialChunkSize = initialChunkSize; this.chunkReaderScheduler = chunkReaderScheduler; Preconditions.checkArgument(initialChunkSize > 0, "Chunk size must be positive"); if (fileChannel.isOpen()) { try { final BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class); fileKey = attr.fileKey(); if (initialReadPosition == FileInput.InitialReadPosition.END) { position = attr.size(); } } catch (IOException e) { log.error("Cannot access file metadata", e); } } }
if (!fileChannel.isOpen()) { log.debug("[{}] File is not open, not performing more reads.", path); fileInput.setReaderFinished(this);
/*************************************** * Returns the channel to be used by this step. This first checks the * currently exexcuting coroutine in the continuation parameter for an * existing {@link #FILE_CHANNEL} relation. If that doesn't exists or the * channel is closed a new {@link AsynchronousFileChannel} will be opened * and stored in the coroutine relation. Using the coroutine to store the * channel allows coroutines to be structured so that multiple subroutines * perform communication on different channels. * * @param rContinuation The continuation to query for an existing channel * * @return The socket channel * * @throws IOException If opening the channel fails */ protected AsynchronousFileChannel getFileChannel( Continuation<?> rContinuation) throws IOException { Coroutine<?, ?> rCoroutine = rContinuation.getCurrentCoroutine(); AsynchronousFileChannel rChannel = rCoroutine.get(FILE_CHANNEL); if (rChannel == null || !rChannel.isOpen()) { rChannel = fGetFileChannel.apply(rContinuation); rCoroutine.set(FILE_CHANNEL, rChannel).annotate(MANAGED); } return rChannel; }
@Override public void stopSending() { if (destination.isOpen()) { try { // The lock will not be released, as you don't release a closed file destination.lock(); destination.force(true); destination.close(); } catch (IOException e) { logger.error("Failed to close {}: {}", fileName, Helpers.resolveThrowableException(e)); logger.catching(Level.DEBUG, e); } } super.stopSending(); }