Package gov.usgs.earthquake.product.io
Class BinaryProductHandler
- java.lang.Object
-
- gov.usgs.earthquake.product.io.BinaryProductHandler
-
- All Implemented Interfaces:
ProductHandler
public class BinaryProductHandler extends java.lang.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())
- Header, exactly 1
- "BEGINPRODUCT" (string)
- ProductId (String)
- Status (String)
- TrackerURL (URL)
- Properties, 0 to many:
- "PROPERTY" (String)
- name (String)
- value (String)
- Links, 0 to many:
- "LINK" (String)
- relation (String)
- href (URI)
- Contents, 0 to many:
- "CONTENT" (String)
- path (String)
- contentType (String)
- lastModified (Date)
- length (Long)
- raw bytes
- Signature Version, 0 or 1.
Note, only sent when version != SIGNATURE_V1 for backward compatibility
- "SIGNATUREVERSION" (String)
- version (String)
- Signature, 0 or 1:
- "SIGNATURE" (String)
- signature (String)
- Footer, exactly 1:
- "ENDPRODUCT" (String)
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CONTENT
CONTENTstatic java.lang.String
FOOTER
ENDPRODUCTstatic java.lang.String
HEADER
HEADER - BEGINPRODUCTstatic java.lang.String
LINK
LINKstatic java.lang.String
PROPERTY
PROPERTYstatic java.lang.String
SIGNATURE
SIGNATUREstatic java.lang.String
SIGNATUREVERSION
SIGNATURE VERSION
-
Constructor Summary
Constructors Constructor Description BinaryProductHandler(java.io.OutputStream out)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Free any resources associated with this source.void
onBeginProduct(ProductId id, java.lang.String status, java.net.URL trackerURL)
A new product is being output.void
onContent(ProductId id, java.lang.String path, Content content)
Product content.void
onEndProduct(ProductId id)
A product is finished being output.void
onLink(ProductId id, java.lang.String relation, java.net.URI href)
A product link.void
onProperty(ProductId id, java.lang.String name, java.lang.String value)
A product property value.void
onSignature(ProductId id, java.lang.String signature)
Product signature.void
onSignatureVersion(ProductId id, CryptoUtils.Version version)
Product signature version.
-
-
-
Field Detail
-
HEADER
public static final java.lang.String HEADER
HEADER - BEGINPRODUCT- See Also:
- Constant Field Values
-
PROPERTY
public static final java.lang.String PROPERTY
PROPERTY- See Also:
- Constant Field Values
-
LINK
public static final java.lang.String LINK
LINK- See Also:
- Constant Field Values
-
CONTENT
public static final java.lang.String CONTENT
CONTENT- See Also:
- Constant Field Values
-
SIGNATUREVERSION
public static final java.lang.String SIGNATUREVERSION
SIGNATURE VERSION- See Also:
- Constant Field Values
-
SIGNATURE
public static final java.lang.String SIGNATURE
SIGNATURE- See Also:
- Constant Field Values
-
FOOTER
public static final java.lang.String FOOTER
ENDPRODUCT- See Also:
- Constant Field Values
-
-
Method Detail
-
onBeginProduct
public void onBeginProduct(ProductId id, java.lang.String status, java.net.URL trackerURL) throws java.lang.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 interfaceProductHandler
- Parameters:
id
- which product.status
- the product's status.trackerURL
- a location to send status updates.- Throws:
java.lang.Exception
- if error occurs
-
onProperty
public void onProperty(ProductId id, java.lang.String name, java.lang.String value) throws java.lang.Exception
Description copied from interface:ProductHandler
A product property value. Products have zero or more properties.- Specified by:
onProperty
in interfaceProductHandler
- Parameters:
id
- which product.name
- the property name.value
- the property value.- Throws:
java.lang.Exception
- if error occurs
-
onLink
public void onLink(ProductId id, java.lang.String relation, java.net.URI href) throws java.lang.Exception
Description copied from interface:ProductHandler
A product link. Products have zero or more links.- Specified by:
onLink
in interfaceProductHandler
- Parameters:
id
- which product.relation
- how the URI is related to this product.href
- the URI that is related to this product.- Throws:
java.lang.Exception
- if error occurs
-
onContent
public void onContent(ProductId id, java.lang.String path, Content content) throws java.lang.Exception
Description copied from interface:ProductHandler
Product content. Products have one or more Contents.- Specified by:
onContent
in interfaceProductHandler
- Parameters:
id
- which product.path
- path to content within product.content
- the product content.- Throws:
java.lang.Exception
- if error occurs
-
onSignatureVersion
public void onSignatureVersion(ProductId id, CryptoUtils.Version version) throws java.lang.Exception
Description copied from interface:ProductHandler
Product signature version.- Specified by:
onSignatureVersion
in interfaceProductHandler
- Parameters:
id
- which product.version
- product version- Throws:
java.lang.Exception
- if error occurs
-
onSignature
public void onSignature(ProductId id, java.lang.String signature) throws java.lang.Exception
Description copied from interface:ProductHandler
Product signature. Producers may optionally sign products to confirm they were the producer.- Specified by:
onSignature
in interfaceProductHandler
- Parameters:
id
- which product.signature
- the product signature, which can be verified using the ProductSigner class.- Throws:
java.lang.Exception
- if error occurs
-
onEndProduct
public void onEndProduct(ProductId id) throws java.lang.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 interfaceProductHandler
- Parameters:
id
- which product.- Throws:
java.lang.Exception
- if error occurs
-
close
public void close()
Free any resources associated with this source.- Specified by:
close
in interfaceProductHandler
-
-