public class WorkflowBundleIO extends Object
WorkflowBundle
s.Modifier and Type | Field and Description |
---|---|
protected ServiceLoader<WorkflowBundleReader> |
readersLoader |
protected ServiceLoader<WorkflowBundleWriter> |
writersLoader |
Constructor and Description |
---|
WorkflowBundleIO() |
Modifier and Type | Method and Description |
---|---|
protected List<WorkflowBundleReader> |
discoverReaders() |
protected List<WorkflowBundleWriter> |
discoverWriters() |
WorkflowBundleReader |
getReaderForMediaType(String mediaType)
Returns a
WorkflowBundleReader for the specified media type. |
List<WorkflowBundleReader> |
getReaders()
Returns all the available
WorkflowBundleReader s. |
WorkflowBundleWriter |
getWriterForMediaType(String mediaType)
Returns a
WorkflowBundleWriter for the specified media type. |
List<WorkflowBundleWriter> |
getWriters()
Returns all the available
WorkflowBundleWriter s. |
String |
guessMediaTypeForSignature(byte[] firstBytes)
Attempt to guess the media type for a stream or file that starts with
these bytes.
|
WorkflowBundle |
readBundle(File bundleFile,
String mediaType)
Reads a file containing a workflow bundle in the specified media type and returns a
WorkflowBundle . |
WorkflowBundle |
readBundle(InputStream inputStream,
String mediaType)
Reads a stream containing a workflow bundle in the specified media type and returns a
WorkflowBundle . |
WorkflowBundle |
readBundle(URL url,
String mediaType)
Reads a URL containing a workflow bundle in the specified media type and returns a
WorkflowBundle . |
void |
setReaders(List<WorkflowBundleReader> readers)
Sets the
WorkflowBundleReader s. |
void |
setWriters(List<WorkflowBundleWriter> writers)
Sets the
WorkflowBundleWriter s. |
void |
writeBundle(WorkflowBundle wfBundle,
File destination,
String mediaType)
Writes a
WorkflowBundle to a file with specified media type. |
void |
writeBundle(WorkflowBundle wfBundle,
OutputStream output,
String mediaType)
Writes a
WorkflowBundle to a stream with specified media type. |
protected ServiceLoader<WorkflowBundleWriter> writersLoader
protected ServiceLoader<WorkflowBundleReader> readersLoader
protected List<WorkflowBundleReader> discoverReaders()
protected List<WorkflowBundleWriter> discoverWriters()
public WorkflowBundleReader getReaderForMediaType(String mediaType)
WorkflowBundleReader
for the specified media type.
If there is more than one WorkflowBundleReader
for the specified media type the
first reader discovered is returned. Subsequent calls to this method may return a different
reader.
If there is no WorkflowBundleReader
for the specified media type
null
is returned.mediaType
- the media type of the WorkflowBundleReader
WorkflowBundleReader
for the specified media typepublic List<WorkflowBundleReader> getReaders()
WorkflowBundleReader
s.WorkflowBundleReader
spublic WorkflowBundleWriter getWriterForMediaType(String mediaType)
WorkflowBundleWriter
for the specified media type.
If there is more than one WorkflowBundleWriter
for the specified media type the
first writer discovered is returned. Subsequent calls to this method may return a different
writer.
If there is no WorkflowBundleWriter
for the specified media type
null
is returned.mediaType
- the media type of the WorkflowBundleWriter
WorkflowBundleWriter
for the specified media typepublic List<WorkflowBundleWriter> getWriters()
WorkflowBundleWriter
s.WorkflowBundleWriter
spublic String guessMediaTypeForSignature(byte[] firstBytes)
All registered getReaders()
are consulted.
Return null
if ambiguous (more than one possibility) or
unknown.
firstBytes
- The initial bytes, at least 512 bytes long unless the resource
is smaller.null
if the bytes were
ambiguous or unknown.public WorkflowBundle readBundle(File bundleFile, String mediaType) throws ReaderException, IOException
WorkflowBundle
.bundleFile
- the file containing the workflow bundlemediaType
- the media type of the workflow bundle. A WorkflowBundleReader
must
exist for this media type.
If null
, the media type will be guessed as with guessMediaTypeForSignature(byte[])
.WorkflowBundle
read from the fileReaderException
- if there is an error parsing the workflow bundleIOException
- if there is an error reading the fileIllegalArgumentException
- if a WorkflowBundleReader
cannot be found for the media typepublic WorkflowBundle readBundle(InputStream inputStream, String mediaType) throws ReaderException, IOException
WorkflowBundle
.inputStream
- the stream containing the workflow bundlemediaType
- the media type of the workflow bundle. A WorkflowBundleReader
must
exist for this media type.
If null
, the media type will be guessed as with guessMediaTypeForSignature(byte[])
.WorkflowBundle
read from the streamReaderException
- if there is an error parsing the workflow bundleIOException
- if there is an error reading from the streamIllegalArgumentException
- if a WorkflowBundleReader
cannot be found for the media typepublic WorkflowBundle readBundle(URL url, String mediaType) throws ReaderException, IOException
WorkflowBundle
.url
- the URL containing the workflow bundlemediaType
- the media type of the workflow bundle. A WorkflowBundleReader
must
exist for this media type
If null
, the media type will
be guessed as with guessMediaTypeForSignature(byte[])
.WorkflowBundle
read from the URLReaderException
- if there is an error parsing the workflow bundleIOException
- if there is an error reading from the streamIllegalArgumentException
- if a WorkflowBundleReader
cannot be found for the media typepublic void setReaders(List<WorkflowBundleReader> readers)
WorkflowBundleReader
s.
This method will normally be called by Spring when wiring beans.
readers
- the WorkflowBundleReader
spublic void setWriters(List<WorkflowBundleWriter> writers)
WorkflowBundleWriter
s.
This method will normally be called by Spring when wiring beans.
readers
- the WorkflowBundleWriter
spublic void writeBundle(WorkflowBundle wfBundle, File destination, String mediaType) throws WriterException, IOException
WorkflowBundle
to a file with specified media type.wfBundle
- the workflow bundle to writedestination
- the file to write the workflow bundle tomediaType
- the media type to write workflow bundle in. A WorkflowBundleWriter
must exist for this media typeWriterException
- if there is an error writing the workflow bundleIOException
- if there is an error writing the fileIllegalArgumentException
- if a WorkflowBundleWriter
cannot be found for the media typepublic void writeBundle(WorkflowBundle wfBundle, OutputStream output, String mediaType) throws WriterException, IOException
WorkflowBundle
to a stream with specified media type.wfBundle
- the workflow bundle to writeoutput
- the stream to write the workflow bundle tomediaType
- the media type to write workflow bundle in. A WorkflowBundleWriter
must exist for this media typeWriterException
- if there is an error writing the workflow bundleIOException
- if there is an error writing to the streamIllegalArgumentException
- if a WorkflowBundleWriter
cannot be found for the media typeCopyright © 2013 myGrid. All rights reserved.