Home / Type/ TarArchive Type — spring-boot Architecture

TarArchive Type — spring-boot Architecture

Architecture documentation for the TarArchive type/interface in TarArchive.java from the spring-boot codebase.

Entity Profile

Source Code

buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/io/TarArchive.java lines 37–149

@FunctionalInterface
public interface TarArchive {

	/**
	 * {@link Instant} that can be used to normalize TAR files so all entries have the
	 * same modification time.
	 */
	Instant NORMALIZED_TIME = OffsetDateTime.of(1980, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC).toInstant();

	/**
	 * Write the TAR archive to the given output stream.
	 * @param outputStream the output stream to write to
	 * @throws IOException on IO error
	 */
	void writeTo(OutputStream outputStream) throws IOException;

	/**
	 * Return the compression being used with the tar archive.
	 * @return the used compression
	 * @since 3.2.6
	 */
	default Compression getCompression() {
		return Compression.NONE;
	}

	/**
	 * Factory method to create a new {@link TarArchive} instance with a specific layout.
	 * @param layout the TAR layout
	 * @return a new {@link TarArchive} instance
	 */
	static TarArchive of(IOConsumer<Layout> layout) {
		return (outputStream) -> {
			TarLayoutWriter writer = new TarLayoutWriter(outputStream);
			layout.accept(writer);
			writer.finish();
		};
	}

	/**
	 * Factory method to adapt a ZIP file to {@link TarArchive}.
	 * @param zip the source zip file
	 * @param owner the owner of the entries in the TAR
	 * @return a new {@link TarArchive} instance
	 */
	static TarArchive fromZip(File zip, Owner owner) {
		return new ZipFileTarArchive(zip, owner);
	}

	/**
	 * Factory method to adapt a ZIP file to {@link TarArchive}. Assumes that
	 * {@link #writeTo(OutputStream)} will only be called once.
	 * @param inputStream the source input stream
	 * @param compression the compression used
	 * @return a new {@link TarArchive} instance
	 * @since 3.2.6
	 */
	static TarArchive fromInputStream(InputStream inputStream, Compression compression) {
		return new TarArchive() {

			@Override
			public void writeTo(OutputStream outputStream) throws IOException {
				StreamUtils.copy(compression.uncompress(inputStream), outputStream);
			}

			@Override
			public Compression getCompression() {
				return compression;
			}

		};
	}

	/**
	 * Compression type applied to the archive.
	 *
	 * @since 3.2.6
	 */
	enum Compression {

		/**
		 * The tar file is not compressed.
		 */
		NONE((inputStream) -> inputStream),

		/**
		 * The tar file is compressed using gzip.
		 */
		GZIP(GZIPInputStream::new),

		/**
		 * The tar file is compressed using zstd.
		 */
		ZSTD("zstd compression is not supported");

		private final ThrowingFunction<InputStream, InputStream> uncompressor;

		Compression(String uncompressError) {
			this((inputStream) -> {
				throw new IllegalStateException(uncompressError);
			});
		}

		Compression(ThrowingFunction<InputStream, InputStream> wrapper) {
			this.uncompressor = wrapper;
		}

		InputStream uncompress(InputStream inputStream) {
			return this.uncompressor.apply(inputStream);
		}

	}

}

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free