Class WaczWriter

java.lang.Object
org.netpreserve.jwarc.WaczWriter
All Implemented Interfaces:
Closeable, AutoCloseable

public class WaczWriter extends Object implements Closeable
Writer for Web Archive Collection Zipped (WACZ) files. EXPERIMENTAL API: May change or be removed without notice.
See Also:
  • Constructor Details

  • Method Details

    • writeResource

      public void writeResource(String path, Path source) throws IOException
      Writes the content of the provided source file to a WACZ resource at the specified path. The source file is read twice as the zip CRC needs to be calculated before writing the ZIP entry.
      Parameters:
      path - the path of the resource where the content will be written
      source - the Path of the file whose content is to be copied to the resource
      Throws:
      IOException - if an I/O error occurs while writing the resource or reading the source file
      IllegalArgumentException - if a resource with the same path has already been written
      IllegalStateException - if the WACZ file has already been finished
    • addPage

      public void addPage(String url, Instant ts, String title) throws IOException
      Adds a page entry to pages.jsonl.
      Parameters:
      url - the URL of the page
      ts - the timestamp in RFC3339 format
      title - an optional title for the page
      Throws:
      IOException
    • finish

      public void finish() throws IOException
      Finishes writing the WACZ file without closing the underlying output stream.
      Throws:
      IOException - if an I/O error occurs
    • close

      public void close() throws IOException
      Finishes writing the WACZ file and closes the underlying output stream.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - if an I/O error occurs
    • set

      public void set(String name, Object value)
      Sets a metadata property to be included in datapackage.json.
      Parameters:
      name - the name of the property to be set
      value - the value of the property to be set (must be JSON serializable)
    • setAutoPages

      public void setAutoPages(boolean enabled)
      Enables or disables automatic detection of pages from WARC records. If disabled, only pages added via addPage(String, Instant, String) will be included.