Class HttpByteArrayCacheEntrySerializer
- java.lang.Object
-
- org.apache.hc.client5.http.impl.cache.HttpByteArrayCacheEntrySerializer
-
- All Implemented Interfaces:
HttpCacheEntrySerializer<byte[]>
@Contract(threading=STATELESS) public class HttpByteArrayCacheEntrySerializer extends java.lang.Object implements HttpCacheEntrySerializer<byte[]>
This class implements theHttpCacheEntrySerializerinterface, which defines the contract for HTTP cache entry serialization and deserialization. It also includes a default buffer size of 8192 bytes, which can be overridden by specifying a different buffer size in the constructor.- Since:
- 5.4
-
-
Field Summary
Fields Modifier and Type Field Description private intbufferSizeprivate static intDEFAULT_BUFFER_SIZEThe default buffer size used for I/O operations, set to 8192 bytes.(package private) static java.lang.StringHC_CACHE_KEY(package private) static java.lang.StringHC_CACHE_LENGTH(package private) static java.lang.StringHC_CACHE_VERSION(package private) static java.lang.StringHC_CACHE_VERSION_LINE(package private) static java.lang.StringHC_REQUEST_INSTANT(package private) static java.lang.StringHC_RESPONSE_INSTANT(package private) static java.lang.StringHC_VARIANTstatic HttpByteArrayCacheEntrySerializerINSTANCEDefault instance ofHttpByteArrayCacheEntrySerializer.private org.apache.hc.core5.http.message.LineFormatterlineFormatterprivate org.apache.hc.core5.http.message.LineParserlineParserprivate static org.slf4j.LoggerLOG
-
Constructor Summary
Constructors Constructor Description HttpByteArrayCacheEntrySerializer()Constructs a new instance ofHttpByteArrayCacheEntrySerializerwith a default buffer size.HttpByteArrayCacheEntrySerializer(int bufferSize)Constructs a HttpByteArrayCacheEntrySerializer with the specified buffer size.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private static java.time.InstantasInstant(java.lang.String value)private static longasLong(java.lang.String value)private static java.lang.StringasStr(long value)private static java.lang.StringasStr(java.time.Instant instant)private static voidcheckReadResult(int n)HttpCacheStorageEntrydeserialize(byte[] serializedObject)Deserializes a byte array representation of an HTTP cache storage entry into an instance ofHttpCacheStorageEntry.protected java.io.InputStreammakeByteArrayInputStream(byte[] bytes)Deprecated.Do not use.protected org.apache.hc.core5.http.impl.io.AbstractMessageParser<org.apache.hc.core5.http.ClassicHttpResponse>makeHttpResponseParser()Deprecated.Do not use.protected org.apache.hc.core5.http.impl.io.AbstractMessageWriter<SimpleHttpResponse>makeHttpResponseWriter(org.apache.hc.core5.http.io.SessionOutputBuffer outputBuffer)Deprecated.Do not use.byte[]serialize(HttpCacheStorageEntry storageEntry)Serializes an HttpCacheStorageEntry object into a byte array using an HTTP-like format.
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
DEFAULT_BUFFER_SIZE
private static final int DEFAULT_BUFFER_SIZE
The default buffer size used for I/O operations, set to 8192 bytes.- See Also:
- Constant Field Values
-
HC_CACHE_VERSION
static final java.lang.String HC_CACHE_VERSION
- See Also:
- Constant Field Values
-
HC_CACHE_VERSION_LINE
static final java.lang.String HC_CACHE_VERSION_LINE
- See Also:
- Constant Field Values
-
HC_CACHE_KEY
static final java.lang.String HC_CACHE_KEY
- See Also:
- Constant Field Values
-
HC_CACHE_LENGTH
static final java.lang.String HC_CACHE_LENGTH
- See Also:
- Constant Field Values
-
HC_REQUEST_INSTANT
static final java.lang.String HC_REQUEST_INSTANT
- See Also:
- Constant Field Values
-
HC_RESPONSE_INSTANT
static final java.lang.String HC_RESPONSE_INSTANT
- See Also:
- Constant Field Values
-
HC_VARIANT
static final java.lang.String HC_VARIANT
- See Also:
- Constant Field Values
-
INSTANCE
public static final HttpByteArrayCacheEntrySerializer INSTANCE
Default instance ofHttpByteArrayCacheEntrySerializer.
-
lineParser
private final org.apache.hc.core5.http.message.LineParser lineParser
-
lineFormatter
private final org.apache.hc.core5.http.message.LineFormatter lineFormatter
-
bufferSize
private final int bufferSize
-
-
Constructor Detail
-
HttpByteArrayCacheEntrySerializer
public HttpByteArrayCacheEntrySerializer(int bufferSize)
Constructs a HttpByteArrayCacheEntrySerializer with the specified buffer size.- Parameters:
bufferSize- the buffer size to use for serialization and deserialization.
-
HttpByteArrayCacheEntrySerializer
public HttpByteArrayCacheEntrySerializer()
Constructs a new instance ofHttpByteArrayCacheEntrySerializerwith a default buffer size.- See Also:
DEFAULT_BUFFER_SIZE
-
-
Method Detail
-
serialize
public byte[] serialize(HttpCacheStorageEntry storageEntry) throws ResourceIOException
Serializes an HttpCacheStorageEntry object into a byte array using an HTTP-like format.The metadata is encoded into HTTP pseudo-headers for storage.
- Specified by:
serializein interfaceHttpCacheEntrySerializer<byte[]>- Parameters:
storageEntry- the HttpCacheStorageEntry to serialize.- Returns:
- the byte array containing the serialized HttpCacheStorageEntry.
- Throws:
ResourceIOException- if there is an error during serialization.
-
deserialize
public HttpCacheStorageEntry deserialize(byte[] serializedObject) throws ResourceIOException
Deserializes a byte array representation of an HTTP cache storage entry into an instance ofHttpCacheStorageEntry.- Specified by:
deserializein interfaceHttpCacheEntrySerializer<byte[]>- Parameters:
serializedObject- the byte array representation of the HTTP cache storage entry- Returns:
- the deserialized HTTP cache storage entry
- Throws:
ResourceIOException- if an error occurs during deserialization
-
asStr
private static java.lang.String asStr(long value)
-
asStr
private static java.lang.String asStr(java.time.Instant instant)
-
asLong
private static long asLong(java.lang.String value) throws ResourceIOException- Throws:
ResourceIOException
-
asInstant
private static java.time.Instant asInstant(java.lang.String value) throws ResourceIOException- Throws:
ResourceIOException
-
checkReadResult
private static void checkReadResult(int n) throws ResourceIOException- Throws:
ResourceIOException
-
makeByteArrayInputStream
@Deprecated protected java.io.InputStream makeByteArrayInputStream(byte[] bytes)
Deprecated.Do not use.- Returns:
- null
-
makeHttpResponseParser
@Deprecated protected org.apache.hc.core5.http.impl.io.AbstractMessageParser<org.apache.hc.core5.http.ClassicHttpResponse> makeHttpResponseParser()
Deprecated.Do not use.- Returns:
- null
-
makeHttpResponseWriter
@Deprecated protected org.apache.hc.core5.http.impl.io.AbstractMessageWriter<SimpleHttpResponse> makeHttpResponseWriter(org.apache.hc.core5.http.io.SessionOutputBuffer outputBuffer)
Deprecated.Do not use.- Returns:
- null
-
-