Package org.beanio.internal
Class DefaultStreamFactory
- java.lang.Object
-
- org.beanio.StreamFactory
-
- org.beanio.internal.DefaultStreamFactory
-
public class DefaultStreamFactory extends StreamFactory
TheDefaultStreamFactorystores 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 voidaddStream(Stream stream)Adds a stream to this manager.MarshallercreateMarshaller(java.lang.String name)Creates a newMarshallerfor marshalling bean objects.BeanReadercreateReader(java.lang.String name, java.io.Reader in, java.util.Locale locale)Creates a newBeanReaderfor reading from a stream.UnmarshallercreateUnmarshaller(java.lang.String name, java.util.Locale locale)Creates a newUnmarshallerfor unmarshalling records.BeanWritercreateWriter(java.lang.String name, java.io.Writer out)Creates a newBeanWriterfor writing to a stream.voiddefine(StreamBuilder builder)Defines a new stream mapping.protected StreamgetStream(java.lang.String name)Returns the named stream.protected voidinit()This method is invoked after a StreamFactory is loaded and all attributes have been set.booleanisMapped(java.lang.String streamName)Test whether a mapping configuration exists for a named stream.voidload(java.io.InputStream in, java.util.Properties properties)Loads a BeanIO mapping file, and adds the configured streams to this factory.StreamremoveStream(java.lang.String name)Removes the named stream from this manager.voidsetCompiler(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:StreamFactoryThis method is invoked after a StreamFactory is loaded and all attributes have been set.- Overrides:
initin classStreamFactory
-
define
public void define(StreamBuilder builder)
Description copied from class:StreamFactoryDefines a new stream mapping.- Specified by:
definein classStreamFactory- Parameters:
builder- theStreamBuilder
-
load
public void load(java.io.InputStream in, java.util.Properties properties) throws java.io.IOException, BeanIOConfigurationExceptionDescription copied from class:StreamFactoryLoads a BeanIO mapping file, and adds the configured streams to this factory.- Specified by:
loadin classStreamFactory- Parameters:
in- the input stream to read the mapping file fromproperties- userPropertiesfor 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:StreamFactoryCreates a newBeanReaderfor reading from a stream.- Specified by:
createReaderin classStreamFactory- Parameters:
name- the name of the stream in the mapping filein- the input stream to read fromlocale- theLocaleused 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:StreamFactoryCreates a newUnmarshallerfor unmarshalling records.- Specified by:
createUnmarshallerin classStreamFactory- Parameters:
name- the name of the stream in the mapping filelocale- theLocaleused 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:StreamFactoryCreates a newBeanWriterfor writing to a stream.- Specified by:
createWriterin 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:StreamFactoryCreates a newMarshallerfor marshalling bean objects.- Specified by:
createMarshallerin 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- theStreamto 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, ornullif 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:StreamFactoryTest whether a mapping configuration exists for a named stream.- Specified by:
isMappedin classStreamFactory- Parameters:
streamName- the stream name to test for existence- Returns:
trueif a mapping configuration is found for the named stream
-
-