BeanIO 1.2.3

org.beanio
Class StreamFactory

java.lang.Object
  extended by org.beanio.StreamFactory
Direct Known Subclasses:
DefaultStreamFactory

public abstract class StreamFactory
extends Object

A StreamFactory manages stream mapping configurations and is used create BeanWriter and BeanReader instances.

The default BeanIO StreamFactory implementation can be safely shared across multiple threads.

Since:
1.0
Author:
Kevin Seim
See Also:
BeanReader, BeanWriter

Constructor Summary
StreamFactory()
          Constructs a new StreamFactory.
 
Method Summary
 BeanReader createReader(String name, File file)
          Creates a new BeanReader for reading from a file.
 BeanReader createReader(String name, Reader in)
          Creates a new BeanReader for reading from the given input stream.
abstract  BeanReader createReader(String name, Reader in, Locale locale)
          Creates a new BeanReader for reading from a stream.
 BeanReader createReader(String name, String filename)
          Creates a new BeanReader for reading from a file.
 BeanWriter createWriter(String name, File file)
          Creates a new BeanWriter for writing to the given file.
abstract  BeanWriter createWriter(String name, Writer out)
          Creates a new BeanWriter for writing to a stream.
abstract  boolean isMapped(String streamName)
          Test whether a mapping configuration exists for a named stream.
 void load(File file)
          Loads a BeanIO configuration file and adds the configured streams to this factory.
abstract  void load(InputStream in)
          Loads a BeanIO configuration and adds the configured streams to this factory.
 void load(String filename)
          Loads a BeanIO configuration file and adds the configured streams to this factory.
 void loadResource(String resource)
          Loads a BeanIO configuration file from the application classpath.
static StreamFactory newInstance()
          Returns a new StreamFactory instance.
protected abstract  void validateStreamName(String name)
          Deprecated. use isMapped(String)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StreamFactory

public StreamFactory()
Constructs a new StreamFactory.

Method Detail

createReader

public BeanReader createReader(String name,
                               String filename)
                        throws BeanIOException
Creates a new BeanReader for reading from a file.

Parameters:
name - the configured stream mapping name
filename - the name of the file to read
Returns:
the new BeanReader
Throws:
IllegalArgumentException - if there is no stream configured for the given name, or if the stream mapping mode does not support reading an input stream
BeanIOException - if the file is not found

createReader

public BeanReader createReader(String name,
                               File file)
                        throws BeanIOException
Creates a new BeanReader for reading from a file.

Parameters:
name - the configured stream mapping name
file - the file to read
Returns:
the new BeanReader
Throws:
IllegalArgumentException - if there is no stream configured for the given name, or if the stream mapping mode does not support reading an input stream
BeanIOException - if the file is not found

createReader

public BeanReader createReader(String name,
                               Reader in)
                        throws IllegalArgumentException
Creates a new BeanReader for reading from the given input stream.

Parameters:
name - the configured stream mapping name
in - the input stream to read from
Returns:
the new BeanReader
Throws:
IllegalArgumentException - if there is no stream configured for the given name, or if the stream mapping mode does not support reading an input stream

createReader

public abstract BeanReader createReader(String name,
                                        Reader in,
                                        Locale locale)
                                 throws IllegalArgumentException
Creates a new BeanReader for reading from a stream.

Parameters:
name - the configured stream mapping name
in - the input stream to read from
locale - the locale used to format error messages, or if null, Locale.getDefault() is used
Returns:
the new BeanReader
Throws:
IllegalArgumentException - if there is no stream configured for the given name, or if the stream mapping mode does not support reading an input stream

createWriter

public BeanWriter createWriter(String name,
                               File file)
                        throws IllegalArgumentException
Creates a new BeanWriter for writing to the given file.

Parameters:
name - the configured stream mapping name
file - the file to write to
Returns:
the new BeanReader
Throws:
IllegalArgumentException - if there is no stream configured for the given name, or if the stream mapping mode does not support writing to an output stream

createWriter

public abstract BeanWriter createWriter(String name,
                                        Writer out)
                                 throws IllegalArgumentException
Creates a new BeanWriter for writing to a stream.

Parameters:
name - the configured stream mapping name
out - the output stream to write to
Returns:
the new BeanWriter
Throws:
IllegalArgumentException - if there is no stream configured for the given name, or if the stream mapping mode does not support writing to an output stream

loadResource

public void loadResource(String resource)
                  throws BeanIOException,
                         BeanIOConfigurationException
Loads a BeanIO configuration file from the application classpath.

Parameters:
resource - the configuration resource name
Throws:
BeanIOException - if an IOException or other fatal error is caught while loading the file
BeanIOConfigurationException - if the configuration is invalid

load

public void load(String filename)
          throws BeanIOException,
                 BeanIOConfigurationException
Loads a BeanIO configuration file and adds the configured streams to this factory. If the given file name is not found in the file system, the file will be loaded from the classpath.

Parameters:
filename - the name of the BeanIO configuration file to load
Throws:
BeanIOException - if an IOException or other fatal error is caught while loading the file
BeanIOConfigurationException - if the configuration is invalid

load

public void load(File file)
          throws BeanIOException,
                 BeanIOConfigurationException
Loads a BeanIO configuration file and adds the configured streams to this factory.

Parameters:
file - the BeanIO configuration file to load
Throws:
BeanIOException - if an IOException or other fatal error is caught while loading the file
BeanIOConfigurationException - if the configuration is invalid

load

public abstract void load(InputStream in)
                   throws IOException,
                          BeanIOConfigurationException
Loads a BeanIO configuration and adds the configured streams to this factory.

Parameters:
in - the input stream to read the configuration from
Throws:
BeanIOException - if an IOException or other fatal error is caught while reading the input stream
BeanIOConfigurationException - if the configuration is invalid
IOException

newInstance

public static StreamFactory newInstance()
                                 throws BeanIOException
Returns a new StreamFactory instance. An implementation class is loaded using the the BeanIO configuration setting org.beanio.streamFactory.

Returns:
a new StreamFactory
Throws:
BeanIOException - if a StreamFactory could not be created
See Also:
Settings

isMapped

public abstract boolean isMapped(String streamName)
Test whether a mapping configuration exists for a named stream.

Parameters:
streamName - the stream name to test for existence
Returns:
true if a mapping configuration is found for the named stream
Since:
1.2

validateStreamName

protected abstract void validateStreamName(String name)
                                    throws IllegalArgumentException
Deprecated. use isMapped(String)

Validates a stream name.

Parameters:
name - the stream name to validate
Throws:
IllegalArgumentException - if there is no stream configured with this name

BeanIO 1.2.3

Copyright © 2010-2012 Kevin Seim