Top Description Inners Fields Constructors Methods
io.undertow.server.handlers.encoding

public Class ContentEncodedResourceManager

extends Object
Class Inheritance
Imports
io.undertow.UndertowLogger, io.undertow.predicate.Predicate, io.undertow.server.HttpServerExchange, io.undertow.server.handlers.resource.CachingResourceManager, .Resource, io.undertow.util.ImmediateConduitFactory, org.xnio.IoUtils, .XnioIoThread, .XnioWorker, org.xnio.channels.StreamSourceChannel, org.xnio.conduits.ConduitStreamSinkChannel, .Conduits, .StreamSinkConduit, .WriteReadyHandler, java.io.IOException, .OutputStream, java.nio.ByteBuffer, java.nio.channels.FileChannel, java.nio.file.Files, .Path, .StandardOpenOption, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, .TimeUnit

Class that provides a way of serving pre-encoded resources.
Author
Stuart Douglas

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private final ContentEncodingRepository
private final CachingResourceManager
private final Path
private final Predicate
private final ConcurrentMap<ContentEncodedResourceManager.LockKey, Object>
private final int
private final int

Constructor Summary

AccessConstructor and Description
public
ContentEncodedResourceManager(Path encodedResourcesRoot, CachingResourceManager encodedResourceManager, ContentEncodingRepository contentEncodingRepository, int minResourceSize, int maxResourceSize, Predicate encodingAllowed)

Method Summary

Modifier and TypeMethod and Description
public ContentEncodedResource
getResource(final Resource resource, final HttpServerExchange exchange)

Gets a pre-encoded resource.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contentEncodingRepositoryback to summary
private final ContentEncodingRepository contentEncodingRepository
encodedback to summary
private final CachingResourceManager encoded
encodedResourcesRootback to summary
private final Path encodedResourcesRoot
encodingAllowedback to summary
private final Predicate encodingAllowed
fileLocksback to summary
private final ConcurrentMap<ContentEncodedResourceManager.LockKey, Object> fileLocks
maxResourceSizeback to summary
private final int maxResourceSize
minResourceSizeback to summary
private final int minResourceSize

Constructor Detail

ContentEncodedResourceManagerback to summary
public ContentEncodedResourceManager(Path encodedResourcesRoot, CachingResourceManager encodedResourceManager, ContentEncodingRepository contentEncodingRepository, int minResourceSize, int maxResourceSize, Predicate encodingAllowed)

Method Detail

getResourceback to summary
public ContentEncodedResource getResource(final Resource resource, final HttpServerExchange exchange) throws IOException

Gets a pre-encoded resource.

Todo

blocking / non-blocking semantics

io.undertow.server.handlers.encoding back to summary

private final Class ContentEncodedResourceManager.FileConduitTarget

extends Object
implements StreamSinkConduit
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.encoding.ContentEncodedResourceManager.FileConduitTarget
All Implemented Interfaces
org.xnio.conduits.StreamSinkConduit, org.xnio.conduits.SinkConduit, org.xnio.conduits.Conduit

Field Summary

Modifier and TypeField and Description
private final HttpServerExchange
private final FileChannel
private WriteReadyHandler
private boolean

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
awaitWritable()

Implements org.xnio.conduits.SinkConduit.awaitWritable.

Block until this channel becomes writable again.

public void
awaitWritable(long
the time to wait
l
,
TimeUnit
the time unit
timeUnit
)

Implements org.xnio.conduits.SinkConduit.awaitWritable.

Block until this conduit becomes writable again, or until the timeout expires.

public boolean
flush()

Implements org.xnio.conduits.SinkConduit.flush.

Flush out any unwritten, buffered output.

public XnioWorker
getWorker()

Implements org.xnio.conduits.Conduit.getWorker.

Get the XNIO worker associated with this conduit.

public XnioIoThread
getWriteThread()

Implements org.xnio.conduits.SinkConduit.getWriteThread.

Get the write thread for this conduit.

public boolean
isWriteResumed()

Implements org.xnio.conduits.SinkConduit.isWriteResumed.

Determine whether write notifications are currently enabled.

public boolean
isWriteShutdown()

Implements org.xnio.conduits.SinkConduit.isWriteShutdown.

Determine whether writes have been fully shut down on this conduit.

public void
resumeWrites()

Implements org.xnio.conduits.SinkConduit.resumeWrites.

Indicate that the conduit's WriteReadyHandler should be invoked as soon as data can be written without blocking.

public void
setWriteReadyHandler(WriteReadyHandler
the filter to receive readiness notifications
writeReadyHandler
)

Implements org.xnio.conduits.SinkConduit.setWriteReadyHandler.

Set the handler which should receive readiness notifications.

public void
suspendWrites()

Implements org.xnio.conduits.SinkConduit.suspendWrites.

Indicate that calling the conduit's WriteReadyHandler should be suspended.

public void
terminateWrites()

Implements org.xnio.conduits.SinkConduit.terminateWrites.

Signal that no more write data is forthcoming.

public long
transferFrom(FileChannel
the file to read from
fileChannel
,
long
the position within the file from which the transfer is to begin
l
,
long
the number of bytes to be transferred
l2
)

Implements org.xnio.conduits.StreamSinkConduit.transferFrom.

Transfer bytes into this conduit from the given file.

public long
transferFrom(StreamSourceChannel
the source to read from
streamSourceChannel
,
long
the number of bytes to be transferred
l
,
ByteBuffer
the buffer to copy through.
byteBuffer
)

Implements org.xnio.conduits.StreamSinkConduit.transferFrom.

Transfers bytes from the given channel source.

public void
truncateWrites()

Implements org.xnio.conduits.SinkConduit.truncateWrites.

Terminate writes and discard any outstanding write data.

public void
wakeupWrites()

Implements org.xnio.conduits.SinkConduit.wakeupWrites.

Indicate that the conduit's WriteReadyHandler should be invoked immediately, and then again as soon as data can be written without blocking.

public int
write(ByteBuffer
the buffer containing data to write
byteBuffer
)

Implements org.xnio.conduits.StreamSinkConduit.write.

Writes a sequence of bytes to this conduit from the given buffer.

public long
write(ByteBuffer[]
the buffers containing data to write
byteBuffers
,
int
the offset into the buffer array
i
,
int
the number of buffers to write
i2
)

Implements org.xnio.conduits.StreamSinkConduit.write.

Writes a sequence of bytes to this conduit from the given buffers.

public int
writeFinal(ByteBuffer
The data to write
src
)

Implements org.xnio.conduits.StreamSinkConduit.writeFinal.

Writes some data to the conduit, with the same semantics as write(java.nio.ByteBuffer).

public long
writeFinal(ByteBuffer[]
The buffers from which bytes are to be retrieved
srcs
,
int
The offset within the buffer array of the first buffer from which bytes are to be retrieved; must be non-negative and no larger than srcs.length
offset
,
int
The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset
length
)

Implements org.xnio.conduits.StreamSinkConduit.writeFinal.

Writes some data to the conduit, with the same semantics as write(java.nio.ByteBuffer[], int, int).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

exchangeback to summary
private final HttpServerExchange exchange
fileChannelback to summary
private final FileChannel fileChannel
writeReadyHandlerback to summary
private WriteReadyHandler writeReadyHandler
writesResumedback to summary
private boolean writesResumed

Constructor Detail

FileConduitTargetback to summary
private FileConduitTarget(FileChannel fileChannel, HttpServerExchange exchange)

Method Detail

awaitWritableback to summary
public void awaitWritable() throws IOException

Implements org.xnio.conduits.SinkConduit.awaitWritable.

Doc from org.xnio.conduits.SinkConduit.awaitWritable.

Block until this channel becomes writable again. This method may return spuriously before the channel becomes writable.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
awaitWritableback to summary
public void awaitWritable(long l, TimeUnit timeUnit) throws IOException

Implements org.xnio.conduits.SinkConduit.awaitWritable.

Doc from org.xnio.conduits.SinkConduit.awaitWritable.

Block until this conduit becomes writable again, or until the timeout expires. This method may return spuriously before the conduit becomes writable or the timeout expires.

Parameters
l:long

the time to wait

timeUnit:TimeUnit

the time unit

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
flushback to summary
public boolean flush() throws IOException

Implements org.xnio.conduits.SinkConduit.flush.

Doc from org.xnio.conduits.SinkConduit.flush.

Flush out any unwritten, buffered output.

Returns:boolean

true if everything is flushed, false otherwise

Annotations
@Override
Exceptions
IOException:
if flush fails
getWorkerback to summary
public XnioWorker getWorker()

Implements org.xnio.conduits.Conduit.getWorker.

Doc from org.xnio.conduits.Conduit.getWorker.

Get the XNIO worker associated with this conduit.

Returns:XnioWorker

the XNIO worker associated with this conduit

Annotations
@Override
getWriteThreadback to summary
public XnioIoThread getWriteThread()

Implements org.xnio.conduits.SinkConduit.getWriteThread.

Doc from org.xnio.conduits.SinkConduit.getWriteThread.

Get the write thread for this conduit.

Returns:XnioIoThread

the thread, or null if none is configured or available

Annotations
@Override
isWriteResumedback to summary
public boolean isWriteResumed()

Implements org.xnio.conduits.SinkConduit.isWriteResumed.

Doc from org.xnio.conduits.SinkConduit.isWriteResumed.

Determine whether write notifications are currently enabled.

Returns:boolean

true if write notifications are enabled

Annotations
@Override
isWriteShutdownback to summary
public boolean isWriteShutdown()

Implements org.xnio.conduits.SinkConduit.isWriteShutdown.

Doc from org.xnio.conduits.SinkConduit.isWriteShutdown.

Determine whether writes have been fully shut down on this conduit.

Returns:boolean

true if writes are fully shut down, false otherwise

Annotations
@Override
resumeWritesback to summary
public void resumeWrites()

Implements org.xnio.conduits.SinkConduit.resumeWrites.

Doc from org.xnio.conduits.SinkConduit.resumeWrites.

Indicate that the conduit's WriteReadyHandler should be invoked as soon as data can be written without blocking.

Annotations
@Override
setWriteReadyHandlerback to summary
public void setWriteReadyHandler(WriteReadyHandler writeReadyHandler)

Implements org.xnio.conduits.SinkConduit.setWriteReadyHandler.

Doc from org.xnio.conduits.SinkConduit.setWriteReadyHandler.

Set the handler which should receive readiness notifications. A filter may pass this invocation on to the filter it wraps, or it may substitute itself.

Parameters
writeReadyHandler:WriteReadyHandler

the filter to receive readiness notifications

Annotations
@Override
suspendWritesback to summary
public void suspendWrites()

Implements org.xnio.conduits.SinkConduit.suspendWrites.

Doc from org.xnio.conduits.SinkConduit.suspendWrites.

Indicate that calling the conduit's WriteReadyHandler should be suspended.

Annotations
@Override
terminateWritesback to summary
public void terminateWrites() throws IOException

Implements org.xnio.conduits.SinkConduit.terminateWrites.

Doc from org.xnio.conduits.SinkConduit.terminateWrites.

Signal that no more write data is forthcoming. The conduit must be flush()ed before it is considered to be shut down.

Annotations
@Override
transferFromback to summary
public long transferFrom(FileChannel fileChannel, long l, long l2) throws IOException

Implements org.xnio.conduits.StreamSinkConduit.transferFrom.

Doc from org.xnio.conduits.StreamSinkConduit.transferFrom.

Transfer bytes into this conduit from the given file.

Parameters
fileChannel:FileChannel

the file to read from

l:long

the position within the file from which the transfer is to begin

l2:long

the number of bytes to be transferred

Returns:long

the number of bytes (possibly 0) that were actually transferred

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
transferFromback to summary
public long transferFrom(StreamSourceChannel streamSourceChannel, long l, ByteBuffer byteBuffer) throws IOException

Implements org.xnio.conduits.StreamSinkConduit.transferFrom.

Doc from org.xnio.conduits.StreamSinkConduit.transferFrom.

Transfers bytes from the given channel source. On entry, throughBuffer will be cleared. On exit, the buffer will be flipped for emptying, and may be empty or may contain data. If this method returns a value less than count, then the remaining data in throughBuffer may contain data read from source which must be written to this channel to complete the operation.

Parameters
streamSourceChannel:StreamSourceChannel

the source to read from

l:long

the number of bytes to be transferred

byteBuffer:ByteBuffer

the buffer to copy through.

Returns:long

the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
truncateWritesback to summary
public void truncateWrites() throws IOException

Implements org.xnio.conduits.SinkConduit.truncateWrites.

Doc from org.xnio.conduits.SinkConduit.truncateWrites.

Terminate writes and discard any outstanding write data. The conduit is terminated and flushed regardless of the outcome of this method.

Annotations
@Override
Exceptions
IOException:
if channel termination failed for some reason
wakeupWritesback to summary
public void wakeupWrites()

Implements org.xnio.conduits.SinkConduit.wakeupWrites.

Doc from org.xnio.conduits.SinkConduit.wakeupWrites.

Indicate that the conduit's WriteReadyHandler should be invoked immediately, and then again as soon as data can be written without blocking.

Annotations
@Override
writeback to summary
public int write(ByteBuffer byteBuffer) throws IOException

Implements org.xnio.conduits.StreamSinkConduit.write.

Doc from org.xnio.conduits.StreamSinkConduit.write.

Writes a sequence of bytes to this conduit from the given buffer.

Parameters
byteBuffer:ByteBuffer

the buffer containing data to write

Returns:int

the number of bytes written, possibly 0

Annotations
@Override
Exceptions
IOException:
if an error occurs
writeback to summary
public long write(ByteBuffer[] byteBuffers, int i, int i2) throws IOException

Implements org.xnio.conduits.StreamSinkConduit.write.

Doc from org.xnio.conduits.StreamSinkConduit.write.

Writes a sequence of bytes to this conduit from the given buffers.

Parameters
byteBuffers:ByteBuffer[]

the buffers containing data to write

i:int

the offset into the buffer array

i2:int

the number of buffers to write

Returns:long

the number of bytes written, possibly 0

Annotations
@Override
Exceptions
IOException:
if an error occurs
writeFinalback to summary
public int writeFinal(ByteBuffer src) throws IOException

Implements org.xnio.conduits.StreamSinkConduit.writeFinal.

Doc from org.xnio.conduits.StreamSinkConduit.writeFinal.

Writes some data to the conduit, with the same semantics as write(java.nio.ByteBuffer). If all the data is written out then the conduit will have its writes terminated. Semantically this method is equivalent to: int rem = src.remaining(); int written = conduit.write(src); if(written == rem) { conduit.terminateWrites() }

Parameters
src:ByteBuffer

The data to write

Returns:int

The amount of data that was actually written.

Annotations
@Override
writeFinalback to summary
public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException

Implements org.xnio.conduits.StreamSinkConduit.writeFinal.

Doc from org.xnio.conduits.StreamSinkConduit.writeFinal.

Writes some data to the conduit, with the same semantics as write(java.nio.ByteBuffer[], int, int). If all the data is written out then the conduit will have its writes terminated.

Parameters
srcs:ByteBuffer[]

The buffers from which bytes are to be retrieved

offset:int

The offset within the buffer array of the first buffer from which bytes are to be retrieved; must be non-negative and no larger than srcs.length

length:int

The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset

Returns:long

The amount of data that was actually written

Annotations
@Override
io.undertow.server.handlers.encoding back to summary

private final Class ContentEncodedResourceManager.LockKey

extends Object
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.encoding.ContentEncodedResourceManager.LockKey

Field Summary

Modifier and TypeField and Description
private final String
private final String

Constructor Summary

AccessConstructor and Description
private
LockKey(String path, String encoding)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

encodingback to summary
private final String encoding
pathback to summary
private final String path

Constructor Detail

LockKeyback to summary
private LockKey(String path, String encoding)

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override