Class BinaryProductHandler

java.lang.Object
gov.usgs.earthquake.product.io.BinaryProductHandler
All Implemented Interfaces:
ProductHandler

public class BinaryProductHandler extends Object implements ProductHandler
Generator of binary format for product data. Binary representation of data types:
Integer
4-bytes
Long
8-bytes
Date
Long (Date.getTime())
byte[]
Integer length, raw bytes
String
byte[] (String.getBytes(StandardCharsets.UTF_8))
URL/URI
String (URL.toString())
Product is stored in this order:
  1. Header, exactly 1
    1. "BEGINPRODUCT" (string)
    2. ProductId (String)
    3. Status (String)
  2. Properties, 0 to many:
    1. "PROPERTY" (String)
    2. name (String)
    3. value (String)
  3. Links, 0 to many:
    1. "LINK" (String)
    2. relation (String)
    3. href (URI)
  4. Contents, 0 to many:
    1. "CONTENT" (String)
    2. path (String)
    3. contentType (String)
    4. lastModified (Date)
    5. length (Long)
    6. raw bytes
  5. Signature Version, 0 or 1. Note, only sent when version != SIGNATURE_V1 for backward compatibility
    1. "SIGNATUREVERSION" (String)
    2. version (String)
  6. Signature, 0 or 1:
    1. "SIGNATURE" (String)
    2. signature (String)
  7. Footer, exactly 1:
    1. "ENDPRODUCT" (String)
  • Field Details

  • Constructor Details

    • BinaryProductHandler

      public BinaryProductHandler(OutputStream out)
      Constructor. Sets up a new BinaryIO
      Parameters:
      out - an OutputStream
  • Method Details

    • onBeginProduct

      public void onBeginProduct(ProductId id, String status) throws Exception
      Description copied from interface: ProductHandler
      A new product is being output. The ProductHandler should expect calls to other on-Methods until the onEndProduct method is called. No calls to other on-Methods will occur before onBeginProduct.
      Specified by:
      onBeginProduct in interface ProductHandler
      Parameters:
      id - which product.
      status - the product's status.
      Throws:
      Exception - if error occurs
    • onProperty

      public void onProperty(ProductId id, String name, String value) throws Exception
      Description copied from interface: ProductHandler
      A product property value. Products have zero or more properties.
      Specified by:
      onProperty in interface ProductHandler
      Parameters:
      id - which product.
      name - the property name.
      value - the property value.
      Throws:
      Exception - if error occurs
    • onLink

      public void onLink(ProductId id, String relation, URI href) throws Exception
      Description copied from interface: ProductHandler
      A product link. Products have zero or more links.
      Specified by:
      onLink in interface ProductHandler
      Parameters:
      id - which product.
      relation - how the URI is related to this product.
      href - the URI that is related to this product.
      Throws:
      Exception - if error occurs
    • onContent

      public void onContent(ProductId id, String path, Content content) throws Exception
      Description copied from interface: ProductHandler
      Product content. Products have one or more Contents.
      Specified by:
      onContent in interface ProductHandler
      Parameters:
      id - which product.
      path - path to content within product.
      content - the product content.
      Throws:
      Exception - if error occurs
    • onSignatureVersion

      public void onSignatureVersion(ProductId id, CryptoUtils.Version version) throws Exception
      Description copied from interface: ProductHandler
      Product signature version.
      Specified by:
      onSignatureVersion in interface ProductHandler
      Parameters:
      id - which product.
      version - product version
      Throws:
      Exception - if error occurs
    • onSignature

      public void onSignature(ProductId id, String signature) throws Exception
      Description copied from interface: ProductHandler
      Product signature. Producers may optionally sign products to confirm they were the producer.
      Specified by:
      onSignature in interface ProductHandler
      Parameters:
      id - which product.
      signature - the product signature, which can be verified using the ProductSigner class.
      Throws:
      Exception - if error occurs
    • onSignatureHistory

      public void onSignatureHistory(ProductId id, List<ProductSignature> signatureHistory) throws Exception
      Description copied from interface: ProductHandler
      Product signature history.
      Specified by:
      onSignatureHistory in interface ProductHandler
      Parameters:
      id - which product.
      signatureHistory - signature history of product.
      Throws:
      Exception - if error occurs
    • onEndProduct

      public void onEndProduct(ProductId id) throws Exception
      Description copied from interface: ProductHandler
      A product is finished being output. The ProductHandler should expect no more calls to other on-Methods, except perhaps onBeginProduct again, after the onEndProduct method is called.
      Specified by:
      onEndProduct in interface ProductHandler
      Parameters:
      id - which product.
      Throws:
      Exception - if error occurs
    • close

      public void close()
      Free any resources associated with this source.
      Specified by:
      close in interface ProductHandler