Package org.incenp.obofoundry.sssom.util
Class ReaderFactory
java.lang.Object
org.incenp.obofoundry.sssom.util.ReaderFactory
A class providing helper methods to obtain SSSOM reader objects.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance.ReaderFactory
(boolean useExtension) Creates a new instance that may optionally use a filename’s extension to infer the format of the file. -
Method Summary
Modifier and TypeMethodDescriptionGets a SSSOM reader suitable for the format used in the provided file.getReader
(InputStream stream) Gets a SSSOM reader suitable for the format used in the provided stream.Gets a SSSOM reader suitable for the format used in the provider Reader object.Gets a SSSOM reader suitable for the format used in the provided Reader object.getReader
(Reader reader, SerialisationFormat fmt) Gets a SSSOM reader for the specified reader object and format.Gets a SSSOM reader suitable for the format used in the file with the provided name.Gets a SSSOM reader suitable for the format used in the file with the provided name.getReader
(String filename, boolean allowStdin, SerialisationFormat fmt) Gets a SSSOM reader for the provided file, with a possibly explicitly specified format.Gets a SSSOM reader suitable for the format used in the file with the provided name.Gets a SSSOM reader suitable for the format used in the file with the provided name.getReader
(String filename, String metaFilename, boolean allowStdin, SerialisationFormat fmt) Gets a SSSOM reader suitable for the specified file, with a possibly explicitly specified format.inferFormat
(Reader reader) Peeks inside a Reader object to try and guess the SSSOM serialisation format that is being used.
-
Constructor Details
-
ReaderFactory
public ReaderFactory()Creates a new instance. -
ReaderFactory
public ReaderFactory(boolean useExtension) Creates a new instance that may optionally use a filename’s extension to infer the format of the file.- Parameters:
useExtension
- Iftrue
, the factory will first try to infer the format of a file based on its extension, before peeking at the file’s contents.
-
-
Method Details
-
getReader
Gets a SSSOM reader suitable for the format used in the provided file.- Parameters:
file
- The file for which a SSSOM reader is desired.- Returns:
- A SSSOM reader suitable for the format of the data in the provided file.
- Throws:
IOException
- If any I/O error occurs when trying to read from the provided file.SSSOMFormatException
- If no known serialisation format could be recognised.
-
getReader
Gets a SSSOM reader suitable for the format used in the provided stream.- Parameters:
stream
- The data stream for which a SSSOM reader is desired.- Returns:
- A SSSOM reader suitable for the format of the data in the provided stream.
- Throws:
IOException
- If any I/O error occurs when trying to read from the indicated stream.SSSOMFormatException
- If no known serialisation format could be recognised.
-
getReader
Gets a SSSOM reader suitable for the format used in the file with the provided name.- Parameters:
filename
- The name of the file for which a SSSOM reader is desired.- Returns:
- A SSSOM reader suitable for the format of the data in the indicated file.
- Throws:
IOException
- If any I/O error occurs when trying to read from the indicated file.SSSOMFormatException
- If no known serialisation format could be recognised.
-
getReader
public SSSOMReader getReader(String filename, boolean allowStdin) throws IOException, SSSOMFormatException Gets a SSSOM reader suitable for the format used in the file with the provided name.- Parameters:
filename
- The name of the file for which a SSSOM reader is desired.allowStdin
- Iftrue
, a filename consisting of a single dash (-
) is interpreted as representing the program’s standard input.- Returns:
- A SSSOM reader suitable for the format of the data in the indicated file.
- Throws:
IOException
- If any I/O error occurs when trying to read from the indicated file.SSSOMFormatException
- If no known serialisation format could be recognised.
-
getReader
public SSSOMReader getReader(String filename, boolean allowStdin, SerialisationFormat fmt) throws IOException, SSSOMFormatException Gets a SSSOM reader for the provided file, with a possibly explicitly specified format.- Parameters:
filename
- The name of the file for which a SSSOM reader is desired.allowStdin
- Iftrue
, a filename consisting of a single dash (-
) is interpreted as representing the program's standard input.fmt
- The expected format of the file. Ifnull
, the factory will attempt to automatically determine the format.- Returns:
- A SSSOM reader suitable for the specified file.
- Throws:
IOException
- If any I/O error occurs when trying to read from the indicated file.SSSOMFormatException
- If the format is not explicitly specified and no known format can be determined.
-
getReader
public SSSOMReader getReader(String filename, String metaFilename) throws IOException, SSSOMFormatException Gets a SSSOM reader suitable for the format used in the file with the provided name.- Parameters:
filename
- The name of the file for which a SSSOM reader is desired.metaFilename
- If non-null
, the name of the file containing the dataset metadata. This automatically assumes that the data is in the SSSOM/TSV format, which is the only format allowing to store the metadata in a separate file.- Returns:
- A SSSOM reader suitable for the format of the data in the indicated file.
- Throws:
IOException
- If any I/O error occurs when trying to read from the indicated files.SSSOMFormatException
- If no known serialisation format could be recognised.
-
getReader
public SSSOMReader getReader(String filename, String metaFilename, boolean allowStdin) throws IOException, SSSOMFormatException Gets a SSSOM reader suitable for the format used in the file with the provided name.- Parameters:
filename
- The name of the file for which a SSSOM reader is desired.metaFilename
- If non-null
, the name of the file containing the dataset metadata. This automatically assumes that the data is in the SSSOM/TSV format, which is the only format allowing to store the metadata in a separate file.allowStdin
- Iftrue
, a filename consisting of a single dash (-
) is interpreted as representing the program’s standard input.- Returns:
- A SSSOM reader suitable for the format of the data in the indicated file.
- Throws:
IOException
- If any I/O error occurs when trying to read from the indicate files.SSSOMFormatException
- If no known serialisation format could be recognised.
-
getReader
public SSSOMReader getReader(String filename, String metaFilename, boolean allowStdin, SerialisationFormat fmt) throws IOException, SSSOMFormatException Gets a SSSOM reader suitable for the specified file, with a possibly explicitly specified format.- Parameters:
filename
- The name of the file for which a SSSOM reader is desired.metaFilename
- If non-null
, the name of the file containing the dataset metadata. This automatically assumes that the data is in SSSOM/TSV or SSSOM/CSV format, since other formats do not allow storing the metadata in a separate file.allowStdin
- Iftrue
, a filename consisting of a single dash (-
) is interpreted as representing the program's standard input.fmt
- The expected format of the file. Ifnull
, the factory will attempt to automatically determine the format.- Returns:
- A SSSOM reader for the specified file.
- Throws:
IOException
- If any I/O error occurs when trying to read from the indicated files.SSSOMFormatException
- If the format is not specified and no known format can be determined.
-
getReader
Gets a SSSOM reader suitable for the format used in the provider Reader object.- Parameters:
reader
- The reader for which to obtain a suitable SSSOM reader.- Returns:
- A SSSOM reader suitable for the format of the data in the provided reader.
- Throws:
IOException
- If any I/O error occurs when trying to infer the serialisation format.SSSOMFormatException
- If no known serialisation format could be recognised.
-
getReader
public SSSOMReader getReader(Reader reader, String filename) throws IOException, SSSOMFormatException Gets a SSSOM reader suitable for the format used in the provided Reader object.- Parameters:
reader
- The reader for which to obtain a suitable SSSOM reader.filename
- The filename to use to try automatically locating the external metadata file, if the provided reader contains SSSOM/TSV data without an embedded metadata block. May benull
.- Returns:
- A SSSOM reader suitable for the format of the data in the provided reader.
- Throws:
IOException
- If any I/O error occurs when trying to infer the serialisation format.SSSOMFormatException
- If no known serialisation format could be recognised.
-
getReader
Gets a SSSOM reader for the specified reader object and format.This method does not attempt to automatically determine the format, and instead expects to be given the correct format.
- Parameters:
reader
- The reader to read from.fmt
- The expected serialisation format.- Returns:
- A suitable SSSOM reader.
- Throws:
IOException
- If the serialisation format is not specified.
-
inferFormat
Peeks inside a Reader object to try and guess the SSSOM serialisation format that is being used.This method looks at the first byte of the provided Reader object to try to automatically determine the SSSOM serialisation format.
- Parameters:
reader
- The reader object to peek into.- Returns:
- The serialisation format used, or
null
if it has not been possible to peek inside the reader, or if no known format has been recognised. - Throws:
IOException
- If any I/O error occurred when trying to peek inside the reader.
-