public abstract class HttpFileBuilder extends AbstractHttpFileBuilder
HttpFile from a file, a classpath resource or an HttpData.
// Build from a file.
HttpFile f = HttpFile.builder(Paths.get("/var/www/index.html"))
.lastModified(false)
.setHeader(HttpHeaderNames.CONTENT_LANGUAGE, "en-US")
.build();
// Build from a classpath resource.
HttpFile f = HttpFile.builder(MyClass.class.getClassLoader(), "/foo.txt.gz")
.setHeader(HttpHeaderNames.CONTENT_ENCODING, "gzip")
.build();
// Build from an HttpData. Can be downcast into AggregatedHttpFile.
AggregatedHttpFile f = (AggregatedHttpFile)
HttpFile.builder(HttpData.ofUtf8("content"), System.currentTimeMillis())
.entityTag((pathOrUri, attrs) -> "myCustomEntityTag")
.build();
| Modifier and Type | Method and Description |
|---|---|
HttpFileBuilder |
addHeader(CharSequence name,
Object value)
Adds the specified HTTP header.
|
HttpFileBuilder |
addHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
Adds the specified HTTP headers.
|
HttpFileBuilder |
autoDetectedContentType(boolean contentTypeAutoDetectionEnabled)
Sets whether to set the
"content-type" header automatically based on the extension of the file. |
abstract HttpFile |
build()
Returns a newly created
HttpFile with the properties configured so far. |
HttpFileBuilder |
cacheControl(CacheControl cacheControl)
Sets the
"cache-control" header. |
HttpFileBuilder |
cacheControl(CharSequence cacheControl)
Sets the
"cache-control" header. |
HttpFileBuilder |
clock(Clock clock)
Sets the
Clock that provides the current date and time. |
HttpFileBuilder |
contentType(CharSequence contentType)
Sets the
"content-type" header. |
HttpFileBuilder |
contentType(MediaType contentType)
Sets the
"content-type" header. |
HttpFileBuilder |
date(boolean dateEnabled)
Sets whether to set the
"date" header automatically. |
HttpFileBuilder |
entityTag(BiFunction<String,HttpFileAttributes,String> entityTagFunction)
Sets the function which generates the entity tag that's used for setting the
"etag" header
automatically. |
HttpFileBuilder |
entityTag(boolean enabled)
Sets whether to set the
"etag" header automatically based on the path and attributes of the
file. |
HttpFileBuilder |
lastModified(boolean lastModifiedEnabled)
Sets whether to set the
"last-modified" header automatically. |
static HttpFileBuilder |
of(File file)
Deprecated.
|
static HttpFileBuilder |
of(HttpData data)
Deprecated.
|
static HttpFileBuilder |
of(HttpData data,
long lastModifiedMillis)
Deprecated.
|
static HttpFileBuilder |
of(Path path)
Deprecated.
|
static HttpFileBuilder |
ofResource(ClassLoader classLoader,
String path)
Deprecated.
|
static HttpFileBuilder |
ofResource(String path)
Deprecated.
|
HttpFileBuilder |
setHeader(CharSequence name,
Object value)
Sets the specified HTTP header.
|
HttpFileBuilder |
setHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
Sets the specified HTTP headers.
|
buildHeaders, clock, entityTagFunction, isContentTypeAutoDetectionEnabled, isDateEnabled, isLastModifiedEnabled@Deprecated public static HttpFileBuilder of(File file)
HttpFile.builder(File).@Deprecated public static HttpFileBuilder of(Path path)
HttpFile.builder(Path).@Deprecated public static HttpFileBuilder of(HttpData data)
HttpFile.builder(HttpData).HttpFileBuilder that builds an AggregatedHttpFile from the specified
HttpData. The last modified date of the file is set to 'now'. Note that the build()
method of the returned builder will always return an AggregatedHttpFile, which guarantees
a safe downcast:
AggregatedHttpFile f = (AggregatedHttpFile) HttpFile.builder(HttpData.ofUtf8("foo")).build();
@Deprecated public static HttpFileBuilder of(HttpData data, long lastModifiedMillis)
HttpFile.builder(HttpData, long).HttpFileBuilder that builds an AggregatedHttpFile from the specified
HttpData and lastModifiedMillis. Note that the build() method of the returned
builder will always return an AggregatedHttpFile, which guarantees a safe downcast:
AggregatedHttpFile f = (AggregatedHttpFile) HttpFile.builder(HttpData.ofUtf8("foo"), 1546923055020)
.build();
data - the content of the filelastModifiedMillis - the last modified time represented as the number of milliseconds
since the epoch@Deprecated public static HttpFileBuilder ofResource(String path)
HttpFile.builder(ClassLoader, String).HttpFileBuilder that builds an HttpFile from the classpath resource
at the specified path. This method is a shortcut for
HttpFile.builder(HttpFile.class.getClassLoader(), path).@Deprecated public static HttpFileBuilder ofResource(ClassLoader classLoader, String path)
HttpFile.builder(ClassLoader, String).HttpFileBuilder that builds an HttpFile from the classpath resource
at the specified path using the specified ClassLoader.public abstract HttpFile build()
HttpFile with the properties configured so far. If this builder was
created with HttpFile.builder(HttpData) or HttpFile.builder(HttpData, long),
the returned instance will always be an AggregatedHttpFile.public HttpFileBuilder clock(Clock clock)
AbstractHttpFileBuilderClock that provides the current date and time. By default, Clock.systemUTC()
is used.clock in class AbstractHttpFileBuilderpublic HttpFileBuilder date(boolean dateEnabled)
AbstractHttpFileBuilder"date" header automatically. By default, the "date" header is
set automatically.date in class AbstractHttpFileBuilderpublic HttpFileBuilder lastModified(boolean lastModifiedEnabled)
AbstractHttpFileBuilder"last-modified" header automatically. By default,
the "last-modified" is set automatically.lastModified in class AbstractHttpFileBuilderpublic HttpFileBuilder autoDetectedContentType(boolean contentTypeAutoDetectionEnabled)
AbstractHttpFileBuilder"content-type" header automatically based on the extension of the file.
By default, the "content-type" header is set automatically.autoDetectedContentType in class AbstractHttpFileBuilderpublic HttpFileBuilder entityTag(boolean enabled)
AbstractHttpFileBuilder"etag" header automatically based on the path and attributes of the
file. By default, the "etag" header is set automatically. Use AbstractHttpFileBuilder.entityTag(BiFunction) to
customize how an entity tag is generated.entityTag in class AbstractHttpFileBuilderpublic HttpFileBuilder entityTag(BiFunction<String,HttpFileAttributes,String> entityTagFunction)
AbstractHttpFileBuilder"etag" header
automatically.entityTag in class AbstractHttpFileBuilderentityTagFunction - the entity tag function that generates the entity tag, or null
to disable setting the "etag" header.public HttpFileBuilder addHeader(CharSequence name, Object value)
AbstractHttpFileBuilderaddHeader in class AbstractHttpFileBuilderpublic HttpFileBuilder addHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
AbstractHttpFileBuilderaddHeaders in class AbstractHttpFileBuilderpublic HttpFileBuilder setHeader(CharSequence name, Object value)
AbstractHttpFileBuildersetHeader in class AbstractHttpFileBuilderpublic HttpFileBuilder setHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
AbstractHttpFileBuildersetHeaders in class AbstractHttpFileBuilderpublic HttpFileBuilder contentType(MediaType contentType)
AbstractHttpFileBuilder"content-type" header. This method is a shortcut for:
builder.autoDetectedContentType(false);
builder.setHeader(HttpHeaderNames.CONTENT_TYPE, contentType);
contentType in class AbstractHttpFileBuilderpublic HttpFileBuilder contentType(CharSequence contentType)
AbstractHttpFileBuilder"content-type" header. This method is a shortcut for:
builder.autoDetectedContentType(false);
builder.setHeader(HttpHeaderNames.CONTENT_TYPE, contentType);
contentType in class AbstractHttpFileBuilderpublic HttpFileBuilder cacheControl(CacheControl cacheControl)
AbstractHttpFileBuilder"cache-control" header. This method is a shortcut for:
builder.setHeader(HttpHeaderNames.CACHE_CONTROL, cacheControl);
cacheControl in class AbstractHttpFileBuilderpublic HttpFileBuilder cacheControl(CharSequence cacheControl)
AbstractHttpFileBuilder"cache-control" header. This method is a shortcut for:
builder.setHeader(HttpHeaderNames.CACHE_CONTROL, cacheControl);
cacheControl in class AbstractHttpFileBuilderCopyright © 2020 LeanCloud. All rights reserved.