Package net.officefloor.server.buffer
Class StreamBufferByteSequence
- java.lang.Object
-
- net.officefloor.server.buffer.StreamBufferByteSequence
-
- All Implemented Interfaces:
java.lang.CharSequence
,ByteSequence
public class StreamBufferByteSequence extends java.lang.Object implements ByteSequence, java.lang.CharSequence
ByteSequence
reading fromStreamBuffer
instances.- Author:
- Daniel Sagenschneider
-
-
Field Summary
-
Fields inherited from interface net.officefloor.server.stream.impl.ByteSequence
EMPTY
-
-
Constructor Summary
Constructors Constructor Description StreamBufferByteSequence(StreamBuffer<java.nio.ByteBuffer> buffer, int offset, int length)
Instantiate with the firstStreamBuffer
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
appendStreamBuffer(StreamBuffer<java.nio.ByteBuffer> buffer, int offset, int length)
Appends aStreamBuffer
to thisByteSequence
.byte
byteAt(int index)
Obtains thebyte
at the index.char
charAt(int index)
<T extends java.lang.Throwable>
StreamBufferByteSequencedecodeUri(java.util.function.Function<java.lang.String,T> invalidDecodeExceptionFactory)
Decodes the URI.java.lang.CharSequence
getHttpCharSequence()
int
length()
Obtains the number ofbyte
values in theByteSequence
.<T extends java.lang.Throwable>
StreamBufferByteSequenceremoveQuotes(java.util.function.Supplier<T> invalidValueExceptionFactory)
Removes surrounding HTTP quotes.static void
setMaxByteLength(int length)
Specifies the maximum byte length of anyByteSequence
.java.lang.CharSequence
subSequence(int start, int end)
java.lang.String
toHttpString()
Obtains thisByteSequence
decoded to a HTTPString
.<T extends java.lang.Throwable>
longtoLong(java.util.function.Function<java.lang.Character,T> invalidDigitExceptionFactory)
Obtains thisByteSequence
as along
value.<T extends java.lang.Throwable>
java.lang.StringtoString(java.nio.charset.Charset charset, java.util.function.Function<java.nio.charset.CoderResult,T> invalidValueExceptionFactory)
<T extends java.lang.Throwable>
java.lang.StringtoUriString(java.util.function.Function<java.nio.charset.CoderResult,T> invalidValueExceptionFactory)
Obtains thisByteSequence
decoded to a URIString
.StreamBufferByteSequence
trim()
Trims thisByteSequence
of outer HTTP spaces and tabs.
-
-
-
Constructor Detail
-
StreamBufferByteSequence
public StreamBufferByteSequence(StreamBuffer<java.nio.ByteBuffer> buffer, int offset, int length)
Instantiate with the firstStreamBuffer
.- Parameters:
buffer
- FirstStreamBuffer
of thisByteSequence
.offset
- Offset into theStreamBuffer
to read data.length
- Length of data from theStreamBuffer
.
-
-
Method Detail
-
setMaxByteLength
public static void setMaxByteLength(int length)
Specifies the maximum byte length of anyByteSequence
.- Parameters:
length
- Maximum byte length of anyByteSequence
.
-
appendStreamBuffer
public void appendStreamBuffer(StreamBuffer<java.nio.ByteBuffer> buffer, int offset, int length)
Appends aStreamBuffer
to thisByteSequence
.- Parameters:
buffer
-StreamBuffer
to append to thisByteSequence
.offset
- Offset into theStreamBuffer
to read data.length
- Length of data from theStreamBuffer
.
-
trim
public StreamBufferByteSequence trim()
Trims thisByteSequence
of outer HTTP spaces and tabs.- Returns:
this
.
-
removeQuotes
public <T extends java.lang.Throwable> StreamBufferByteSequence removeQuotes(java.util.function.Supplier<T> invalidValueExceptionFactory) throws T extends java.lang.Throwable
Removes surrounding HTTP quotes.- Type Parameters:
T
- Invalid valueException
type.- Parameters:
invalidValueExceptionFactory
-Supplier
of the invalid valueException
.- Returns:
this
.- Throws:
T
- Invalid valueException
.T extends java.lang.Throwable
-
getHttpCharSequence
public java.lang.CharSequence getHttpCharSequence()
Obtains this
ByteSequence
as aCharSequence
for HTTPCharacter
values.This is for use with
NonMaterialisedHttpHeader
comparing on the name.- Returns:
CharSequence
for HTTPCharacter
values of thisByteSequence
.
-
toHttpString
public java.lang.String toHttpString()
Obtains thisByteSequence
decoded to a HTTPString
.- Returns:
ByteSequence
decoded to a HTTPString
.
-
decodeUri
public <T extends java.lang.Throwable> StreamBufferByteSequence decodeUri(java.util.function.Function<java.lang.String,T> invalidDecodeExceptionFactory) throws T extends java.lang.Throwable
Decodes the URI.- Type Parameters:
T
- Invalid decodeException
type.- Parameters:
invalidDecodeExceptionFactory
-Function
to create an invalid encodingThrowable
.- Returns:
this
.- Throws:
T
- If invalid encoding.T extends java.lang.Throwable
-
toUriString
public <T extends java.lang.Throwable> java.lang.String toUriString(java.util.function.Function<java.nio.charset.CoderResult,T> invalidValueExceptionFactory) throws T extends java.lang.Throwable
Obtains thisByteSequence
decoded to a URIString
.- Type Parameters:
T
- Invalid valueException
type.- Parameters:
invalidValueExceptionFactory
- Factory to create theException
should theByteSequence
not be valid for the URI.- Returns:
ByteSequence
decoded to a URIString
.- Throws:
T
- If invalidByteSequence
for the URI.T extends java.lang.Throwable
-
toString
public <T extends java.lang.Throwable> java.lang.String toString(java.nio.charset.Charset charset, java.util.function.Function<java.nio.charset.CoderResult,T> invalidValueExceptionFactory) throws T extends java.lang.Throwable
- Type Parameters:
T
- Invalid valueException
type.- Parameters:
charset
-Charset
for the decoding theStreamBuffer
data.invalidValueExceptionFactory
- Factory to create theException
should theByteSequence
not be valid for theCharset
.- Returns:
String
value for theStreamBuffer
values.- Throws:
T
- If invalidByteSequence
forCharset
.T extends java.lang.Throwable
-
toLong
public <T extends java.lang.Throwable> long toLong(java.util.function.Function<java.lang.Character,T> invalidDigitExceptionFactory) throws T extends java.lang.Throwable
Obtains thisByteSequence
as along
value.- Type Parameters:
T
- Invalid digitException
type.- Parameters:
invalidDigitExceptionFactory
-Function
to create anThrowable
should there be an invalid HTTP digit.- Returns:
long
value.- Throws:
T
- If invalid value to convert to long.T extends java.lang.Throwable
-
byteAt
public byte byteAt(int index)
Description copied from interface:ByteSequence
Obtains thebyte
at the index.- Specified by:
byteAt
in interfaceByteSequence
- Parameters:
index
- Index of thebyte
.- Returns:
byte
at the index.
-
length
public int length()
Description copied from interface:ByteSequence
Obtains the number ofbyte
values in theByteSequence
.- Specified by:
length
in interfaceByteSequence
- Specified by:
length
in interfacejava.lang.CharSequence
- Returns:
- Number of
byte
values in theByteSequence
.
-
charAt
public char charAt(int index)
- Specified by:
charAt
in interfacejava.lang.CharSequence
-
subSequence
public java.lang.CharSequence subSequence(int start, int end)
- Specified by:
subSequence
in interfacejava.lang.CharSequence
-
-