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
ByteSequencereading fromStreamBufferinstances.- 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 voidappendStreamBuffer(StreamBuffer<java.nio.ByteBuffer> buffer, int offset, int length)Appends aStreamBufferto thisByteSequence.bytebyteAt(int index)Obtains thebyteat the index.charcharAt(int index)<T extends java.lang.Throwable>
StreamBufferByteSequencedecodeUri(java.util.function.Function<java.lang.String,T> invalidDecodeExceptionFactory)Decodes the URI.java.lang.CharSequencegetHttpCharSequence()intlength()Obtains the number ofbytevalues in theByteSequence.<T extends java.lang.Throwable>
StreamBufferByteSequenceremoveQuotes(java.util.function.Supplier<T> invalidValueExceptionFactory)Removes surrounding HTTP quotes.static voidsetMaxByteLength(int length)Specifies the maximum byte length of anyByteSequence.java.lang.CharSequencesubSequence(int start, int end)java.lang.StringtoHttpString()Obtains thisByteSequencedecoded to a HTTPString.<T extends java.lang.Throwable>
longtoLong(java.util.function.Function<java.lang.Character,T> invalidDigitExceptionFactory)Obtains thisByteSequenceas alongvalue.<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 thisByteSequencedecoded to a URIString.StreamBufferByteSequencetrim()Trims thisByteSequenceof 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- FirstStreamBufferof thisByteSequence.offset- Offset into theStreamBufferto 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 aStreamBufferto thisByteSequence.- Parameters:
buffer-StreamBufferto append to thisByteSequence.offset- Offset into theStreamBufferto read data.length- Length of data from theStreamBuffer.
-
trim
public StreamBufferByteSequence trim()
Trims thisByteSequenceof 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 valueExceptiontype.- Parameters:
invalidValueExceptionFactory-Supplierof the invalid valueException.- Returns:
this.- Throws:
T- Invalid valueException.T extends java.lang.Throwable
-
getHttpCharSequence
public java.lang.CharSequence getHttpCharSequence()
Obtains this
ByteSequenceas aCharSequencefor HTTPCharactervalues.This is for use with
NonMaterialisedHttpHeadercomparing on the name.- Returns:
CharSequencefor HTTPCharactervalues of thisByteSequence.
-
toHttpString
public java.lang.String toHttpString()
Obtains thisByteSequencedecoded to a HTTPString.- Returns:
ByteSequencedecoded 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 decodeExceptiontype.- Parameters:
invalidDecodeExceptionFactory-Functionto 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.ThrowableObtains thisByteSequencedecoded to a URIString.- Type Parameters:
T- Invalid valueExceptiontype.- Parameters:
invalidValueExceptionFactory- Factory to create theExceptionshould theByteSequencenot be valid for the URI.- Returns:
ByteSequencedecoded to a URIString.- Throws:
T- If invalidByteSequencefor 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 valueExceptiontype.- Parameters:
charset-Charsetfor the decoding theStreamBufferdata.invalidValueExceptionFactory- Factory to create theExceptionshould theByteSequencenot be valid for theCharset.- Returns:
Stringvalue for theStreamBuffervalues.- Throws:
T- If invalidByteSequenceforCharset.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.ThrowableObtains thisByteSequenceas alongvalue.- Type Parameters:
T- Invalid digitExceptiontype.- Parameters:
invalidDigitExceptionFactory-Functionto create anThrowableshould there be an invalid HTTP digit.- Returns:
longvalue.- Throws:
T- If invalid value to convert to long.T extends java.lang.Throwable
-
byteAt
public byte byteAt(int index)
Description copied from interface:ByteSequenceObtains thebyteat the index.- Specified by:
byteAtin interfaceByteSequence- Parameters:
index- Index of thebyte.- Returns:
byteat the index.
-
length
public int length()
Description copied from interface:ByteSequenceObtains the number ofbytevalues in theByteSequence.- Specified by:
lengthin interfaceByteSequence- Specified by:
lengthin interfacejava.lang.CharSequence- Returns:
- Number of
bytevalues in theByteSequence.
-
charAt
public char charAt(int index)
- Specified by:
charAtin interfacejava.lang.CharSequence
-
subSequence
public java.lang.CharSequence subSequence(int start, int end)- Specified by:
subSequencein interfacejava.lang.CharSequence
-
-