Content Type — spring-boot Architecture
Architecture documentation for the Content type/interface in Content.java from the spring-boot codebase.
Entity Profile
Source Code
buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/io/Content.java lines 36–106
public interface Content {
/**
* The size of the content in bytes.
* @return the content size
*/
int size();
/**
* Write the content to the given output stream.
* @param outputStream the output stream to write to
* @throws IOException on IO error
*/
void writeTo(OutputStream outputStream) throws IOException;
/**
* Create a new {@link Content} from the given UTF-8 string.
* @param string the string to write
* @return a new {@link Content} instance
*/
static Content of(String string) {
Assert.notNull(string, "'string' must not be null");
return of(string.getBytes(StandardCharsets.UTF_8));
}
/**
* Create a new {@link Content} from the given input stream.
* @param bytes the bytes to write
* @return a new {@link Content} instance
*/
static Content of(byte[] bytes) {
Assert.notNull(bytes, "'bytes' must not be null");
return of(bytes.length, () -> new ByteArrayInputStream(bytes));
}
/**
* Create a new {@link Content} from the given file.
* @param file the file to write
* @return a new {@link Content} instance
*/
static Content of(File file) {
Assert.notNull(file, "'file' must not be null");
return of((int) file.length(), () -> new FileInputStream(file));
}
/**
* Create a new {@link Content} from the given input stream. The stream will be closed
* after it has been written.
* @param size the size of the supplied input stream
* @param supplier the input stream supplier
* @return a new {@link Content} instance
*/
static Content of(int size, IOSupplier<InputStream> supplier) {
Assert.isTrue(size >= 0, "'size' must not be negative");
Assert.notNull(supplier, "'supplier' must not be null");
return new Content() {
@Override
public int size() {
return size;
}
@Override
public void writeTo(OutputStream outputStream) throws IOException {
FileCopyUtils.copy(supplier.get(), outputStream);
}
};
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free