[dna-issues] [JBoss JIRA] Resolved: (DNA-260) Add factory method to create a Binary instance from a (local) File

Randall Hauch (JIRA) jira-events at lists.jboss.org
Thu Jan 8 13:18:03 EST 2009


     [ https://jira.jboss.org/jira/browse/DNA-260?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Randall Hauch resolved DNA-260.
-------------------------------

    Resolution: Done


Created the BinaryFactory interface, which extends ValueFactory<Binary> and adds several methods for creating Binary objects from File objects, and from InputStream (or Reader) when then binary's hash is already known.  These latter methods will allow an implementation to maintain a pool of Binary objects keyed by their hash, so that only one Binary object per unique value is needed.  Also added a method to find a Binary value given the hash (so that connectors and clients that know the hash may attempt to reuse an existing Binary value with the same hash, without having to create the InputStream (or Reader), since that may be expensive even if the stream/reader is not used.

None of the factories in 'org.jboss.dna.graph' reuse Binary values, however; they always create a new object.

Also added some better error handling logic in IoUtil - getting an exception when closing a stream (in the finally block) will not stomp on an exception thrown from the try block.

> Add factory method to create a Binary instance from a (local) File
> ------------------------------------------------------------------
>
>                 Key: DNA-260
>                 URL: https://jira.jboss.org/jira/browse/DNA-260
>             Project: DNA
>          Issue Type: Feature Request
>          Components: API, Graph
>    Affects Versions: 0.3
>            Reporter: Randall Hauch
>            Assignee: Randall Hauch
>            Priority: Minor
>             Fix For: 0.4
>
>
> A client sometimes has a file and wants to represent the content of the file with a Binary value object.  Currently, the client would have to obtain an InputStream or a Reader to the file, and create the Binary value object with that.  Then, when somebody wants to read the binary value, they have to create another stream/reader.  Essentially, the content is streamed 1+n times, where n is the number of times the value is read.  This can be very expensive when the size of the file is large (or very large, as in gigabytes).
> By adding a factor method that takes a File object, the factory could optimize the behavior.  Rather than creating a stream/reader to put the content into the Binary value object, the factory could just create a Binary implementation that delegates to a File.  Then, the only time a stream/reader is created is when the client wants to read the value.  In other words, the content is streamed only n times.
> We don't yet have a BinaryFactory interface, and are currently using ValueFactory<Binary>.  Therefore, the first step is to create the BinaryFactory interface and use this in the ValueFactories interface.  (Most uses of the 'getBinaryFactory()' method would not need to change, since they're either just immediately calling 'create(...)' on the returned reference, or are using ValueFactory<Binary>, which would still work.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the dna-issues mailing list