Top Description Fields Constructors Methods
org.eclipse.jetty.io.content

public Class PathContentSource

extends Object
implements Source
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.io.Content.Source
Imports
java.io.IOException, .UncheckedIOException, java.nio.ByteBuffer, java.nio.channels.SeekableByteChannel, java.nio.file.AccessDeniedException, .Files, .NoSuchFileException, .Path, .StandardOpenOption, org.eclipse.jetty.io.ByteBufferPool, .Content, .RetainableByteBuffer, org.eclipse.jetty.util.BufferUtil, .IO, org.eclipse.jetty.util.thread.AutoLock, .SerializedInvoker

A Content.Source that provides the file content of the passed Path.

Field Summary

Modifier and TypeField and Description
private int
private final ByteBufferPool
private SeekableByteChannel
private Runnable
private Content.Chunk
private final SerializedInvoker
private final long
private final AutoLock
private final Path
private long
private boolean

Constructor Summary

AccessConstructor and Description
public
public
PathContentSource(Path path, ByteBufferPool byteBufferPool)

Method Summary

Modifier and TypeMethod and Description
public void
demand(Runnable
the demand callback to invoke where there is a content chunk available
demandCallback
)

Implements org.eclipse.jetty.io.Content.Source.demand.

Demands to invoke the given demand callback parameter when a chunk of content is available.

public void
fail(Throwable
the cause of the failure
failure
)

Implements org.eclipse.jetty.io.Content.Source.fail.

Fails this content source with a last failure chunk, failing and discarding accumulated content chunks that were not yet read.

private Content.Chunk
failure(Throwable failure)

public int
public long
public Path
private void
protected boolean
isReadComplete(long read)

public boolean
protected SeekableByteChannel
open()

public Content.Chunk
read()

Implements org.eclipse.jetty.io.Content.Source.read.

Reads a chunk of content.

protected int
read(SeekableByteChannel channel, ByteBuffer byteBuffer)

public boolean
rewind()

Overrides default org.eclipse.jetty.io.Content.Source.rewind.

Rewinds this content, if possible, so that subsequent reads return chunks starting from the beginning of this content.

private void
runDemandCallback(Runnable demandCallback)

public void
setBufferSize(int bufferSize)

public void
setUseDirectByteBuffers(boolean useDirectByteBuffers)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferSizeback to summary
private int bufferSize
byteBufferPoolback to summary
private final ByteBufferPool byteBufferPool
channelback to summary
private SeekableByteChannel channel
demandCallbackback to summary
private Runnable demandCallback
errorChunkback to summary
private Content.Chunk errorChunk
invokerback to summary
private final SerializedInvoker invoker
lengthback to summary
private final long length
lockback to summary
private final AutoLock lock
pathback to summary
private final Path path
totalReadback to summary
private long totalRead
useDirectByteBuffersback to summary
private boolean useDirectByteBuffers

Constructor Detail

PathContentSourceback to summary
public PathContentSource(Path path)
PathContentSourceback to summary
public PathContentSource(Path path, ByteBufferPool byteBufferPool)

Method Detail

demandback to summary
public void demand(Runnable demandCallback)

Implements org.eclipse.jetty.io.Content.Source.demand.

Doc from org.eclipse.jetty.io.Content.Source.demand.

Demands to invoke the given demand callback parameter when a chunk of content is available.

See how to use this method idiomatically.

Implementations guarantee that calls to this method are safely reentrant so that stack overflows are avoided in the case of mutual recursion between the execution of the Runnable callback and a call to this method. Invocations of the passed Runnable are serialized and a callback for demand call is not invoked until any previous demand callback has returned. Thus the Runnable should not block waiting for a callback of a future demand call.

The demand callback may be invoked spuriously: a subsequent call to read() may return null.

Calling this method establishes a pending demand, which is fulfilled when the demand callback is invoked.

Calling this method when there is already a pending demand results in an IllegalStateException to be thrown.

If the invocation of the demand callback throws an exception, then fail(Throwable) is called.

Parameters
demandCallback:Runnable

the demand callback to invoke where there is a content chunk available

Annotations
@Override
failback to summary
public void fail(Throwable failure)

Implements org.eclipse.jetty.io.Content.Source.fail.

Doc from org.eclipse.jetty.io.Content.Source.fail.

Fails this content source with a last failure chunk, failing and discarding accumulated content chunks that were not yet read.

The failure may be notified to the content reader at a later time, when the content reader reads a content chunk, via a Chunk instance with a non null Chunk#getFailure().

If read() has returned a last chunk, this is a no operation.

Typical failure: the content being aborted by user code, or idle timeouts.

If this method has already been called, then it is a no operation.

Parameters
failure:Throwable

the cause of the failure

Annotations
@Override
failureback to summary
private Content.Chunk failure(Throwable failure)
getBufferSizeback to summary
public int getBufferSize()
getLengthback to summary
public long getLength()

Overrides default org.eclipse.jetty.io.Content.Source.getLength.

Returns:long

Doc from org.eclipse.jetty.io.Content.Source.getLength.

the content length, if known, or -1 if the content length is unknown

Annotations
@Override
getPathback to summary
public Path getPath()
invokeDemandCallbackback to summary
private void invokeDemandCallback()
isReadCompleteback to summary
protected boolean isReadComplete(long read)
isUseDirectByteBuffersback to summary
public boolean isUseDirectByteBuffers()
openback to summary
protected SeekableByteChannel open() throws IOException
readback to summary
public Content.Chunk read()

Implements org.eclipse.jetty.io.Content.Source.read.

Doc from org.eclipse.jetty.io.Content.Source.read.

Reads a chunk of content.

See how to use this method idiomatically.

The returned chunk could be:

  • null, to signal that there isn't a chunk of content available
  • an Chunk instance with non null Chunk#getFailure(), to signal that there was a failure trying to produce a chunk of content, or that the content production has been failed externally
  • a Chunk instance, containing the chunk of content.

Once a read returns an Chunk instance with non-null Chunk#getFailure() then if the failure is last further reads will continue to return the same failure chunk instance, otherwise further read() operations may return different non-failure chunks.

Once a read returns a last chunk, further reads will continue to return a last chunk (although the instance may be different).

The content reader code must ultimately arrange for a call to Chunk#release() on the returned Chunk.

Additionally, prior to the ultimate call to Chunk#release(), the reader code may make additional calls to Chunk#retain(), that must ultimately be matched by a correspondent number of calls to Chunk#release().

Concurrent reads from different threads are not recommended, as they are inherently in a race condition.

Reads performed outside the invocation context of a demand callback are allowed. However, reads performed with a pending demand are inherently in a race condition (the thread that reads with the thread that invokes the demand callback).

Returns:Content.Chunk

a chunk of content, possibly a failure instance, or null

Annotations
@Override
readback to summary
protected int read(SeekableByteChannel channel, ByteBuffer byteBuffer) throws IOException
rewindback to summary
public boolean rewind()

Overrides default org.eclipse.jetty.io.Content.Source.rewind.

Doc from org.eclipse.jetty.io.Content.Source.rewind.

Rewinds this content, if possible, so that subsequent reads return chunks starting from the beginning of this content.

Returns:boolean

true if this content has been rewound, false if this content cannot be rewound

Annotations
@Override
runDemandCallbackback to summary
private void runDemandCallback(Runnable demandCallback)
setBufferSizeback to summary
public void setBufferSize(int bufferSize)
setUseDirectByteBuffersback to summary
public void setUseDirectByteBuffers(boolean useDirectByteBuffers)