Package org.beanio.internal
Class DefaultStreamFactory
- java.lang.Object
-
- org.beanio.StreamFactory
-
- org.beanio.internal.DefaultStreamFactory
-
public class DefaultStreamFactory extends StreamFactory
TheDefaultStreamFactory
stores configured stream definitions used to create bean readers and writers. A single factory instance may be accessed concurrently by multiple threads.- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description DefaultStreamFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addStream(Stream stream)
Adds a stream to this manager.Marshaller
createMarshaller(java.lang.String name)
Creates a newMarshaller
for marshalling bean objects.BeanReader
createReader(java.lang.String name, java.io.Reader in, java.util.Locale locale)
Creates a newBeanReader
for reading from a stream.Unmarshaller
createUnmarshaller(java.lang.String name, java.util.Locale locale)
Creates a newUnmarshaller
for unmarshalling records.BeanWriter
createWriter(java.lang.String name, java.io.Writer out)
Creates a newBeanWriter
for writing to a stream.void
define(StreamBuilder builder)
Defines a new stream mapping.protected Stream
getStream(java.lang.String name)
Returns the named stream.protected void
init()
This method is invoked after a StreamFactory is loaded and all attributes have been set.boolean
isMapped(java.lang.String streamName)
Test whether a mapping configuration exists for a named stream.void
load(java.io.InputStream in, java.util.Properties properties)
Loads a BeanIO mapping file, and adds the configured streams to this factory.Stream
removeStream(java.lang.String name)
Removes the named stream from this manager.void
setCompiler(StreamCompiler compiler)
Sets the mapping compiler to use for compiling streams.-
Methods inherited from class org.beanio.StreamFactory
createReader, createReader, createReader, createUnmarshaller, createWriter, getClassLoader, load, load, load, load, load, loadResource, loadResource, newInstance, newInstance, setClassLoader
-
-
-
-
Method Detail
-
init
protected void init()
Description copied from class:StreamFactory
This method is invoked after a StreamFactory is loaded and all attributes have been set.- Overrides:
init
in classStreamFactory
-
define
public void define(StreamBuilder builder)
Description copied from class:StreamFactory
Defines a new stream mapping.- Specified by:
define
in classStreamFactory
- Parameters:
builder
- theStreamBuilder
-
load
public void load(java.io.InputStream in, java.util.Properties properties) throws java.io.IOException, BeanIOConfigurationException
Description copied from class:StreamFactory
Loads a BeanIO mapping file, and adds the configured streams to this factory.- Specified by:
load
in classStreamFactory
- Parameters:
in
- the input stream to read the mapping file fromproperties
- userProperties
for property substitution- Throws:
BeanIOConfigurationException
- if the mapping file is invalidjava.io.IOException
-
createReader
public BeanReader createReader(java.lang.String name, java.io.Reader in, java.util.Locale locale)
Description copied from class:StreamFactory
Creates a newBeanReader
for reading from a stream.- Specified by:
createReader
in classStreamFactory
- Parameters:
name
- the name of the stream in the mapping filein
- the input stream to read fromlocale
- theLocale
used to format error messages, or null to useLocale.getDefault()
- Returns:
- the created
BeanReader
-
createUnmarshaller
public Unmarshaller createUnmarshaller(java.lang.String name, java.util.Locale locale)
Description copied from class:StreamFactory
Creates a newUnmarshaller
for unmarshalling records.- Specified by:
createUnmarshaller
in classStreamFactory
- Parameters:
name
- the name of the stream in the mapping filelocale
- theLocale
used to format error messages, or null to useLocale.getDefault()
- Returns:
- the created
Unmarshaller
-
createWriter
public BeanWriter createWriter(java.lang.String name, java.io.Writer out)
Description copied from class:StreamFactory
Creates a newBeanWriter
for writing to a stream.- Specified by:
createWriter
in classStreamFactory
- Parameters:
name
- the name of the stream in the mapping fileout
- the output stream to write to- Returns:
- the created
BeanWriter
-
createMarshaller
public Marshaller createMarshaller(java.lang.String name)
Description copied from class:StreamFactory
Creates a newMarshaller
for marshalling bean objects.- Specified by:
createMarshaller
in classStreamFactory
- Parameters:
name
- the name of the stream in the mapping file- Returns:
- the created
Marshaller
-
getStream
protected Stream getStream(java.lang.String name) throws java.lang.IllegalArgumentException
Returns the named stream.- Parameters:
name
- the name of the stream- Returns:
- the
Stream
- Throws:
java.lang.IllegalArgumentException
- if there is no stream configured for the given name
-
addStream
public void addStream(Stream stream)
Adds a stream to this manager.- Parameters:
stream
- theStream
to add
-
removeStream
public Stream removeStream(java.lang.String name)
Removes the named stream from this manager.- Parameters:
name
- the name of the stream to remove- Returns:
- the removed
Stream
, ornull
if the there was no stream for the given name
-
setCompiler
public void setCompiler(StreamCompiler compiler)
Sets the mapping compiler to use for compiling streams.- Parameters:
compiler
- theStreamCompiler
-
isMapped
public boolean isMapped(java.lang.String streamName)
Description copied from class:StreamFactory
Test whether a mapping configuration exists for a named stream.- Specified by:
isMapped
in classStreamFactory
- Parameters:
streamName
- the stream name to test for existence- Returns:
true
if a mapping configuration is found for the named stream
-
-