Package com.cognitect.transit
Class TransitFactory
- java.lang.Object
-
- com.cognitect.transit.TransitFactory
-
public class TransitFactory extends Object
Main entry point for using transit-java library. Provides methods to construct readers and writers, as well as helpers to make various other values.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TransitFactory.Format
Transit formats
-
Constructor Summary
Constructors Constructor Description TransitFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static DefaultReadHandler<TaggedValue<Object>>
defaultDefaultReadHandler()
Returns the DefaultReadHandler that is used by defaultstatic WriteHandler<?,?>
defaultDefaultWriteHandler()
static Map<String,ReadHandler<?,?>>
defaultReadHandlers()
Returns a map of tags to ReadHandlers that is used by defaultstatic Map<Class,WriteHandler<?,?>>
defaultWriteHandlers()
Returns a map of classes to Handlers that is used by defaultstatic Keyword
keyword(Object o)
Converts a string or keyword to a keywordstatic Link
link(URI href, String rel)
Creates a Linkstatic Link
link(URI href, String rel, String name, String prompt, String render)
Creates a Linkstatic Link
link(String href, String rel)
Creates a Linkstatic Link
link(String href, String rel, String name, String prompt, String render)
Creates a Linkstatic Reader
reader(TransitFactory.Format type, InputStream in)
Creates a reader instance.static Reader
reader(TransitFactory.Format type, InputStream in, DefaultReadHandler<?> customDefaultHandler)
Creates a reader instance.static Reader
reader(TransitFactory.Format type, InputStream in, Map<String,ReadHandler<?,?>> customHandlers)
Creates a reader instance.static Reader
reader(TransitFactory.Format type, InputStream in, Map<String,ReadHandler<?,?>> customHandlers, DefaultReadHandler<?> customDefaultHandler)
Creates a reader instance.static Map<String,ReadHandler<?,?>>
readHandlerMap(Map<String,ReadHandler<?,?>> customHandlers)
Creates a read-only Map of String to ReadHandler containing default ReadHandlers with customHandlers merged in.static Symbol
symbol(Object o)
Converts a string or a symbol to a symbolstatic <T> TaggedValue<T>
taggedValue(String tag, T rep)
Creates a TaggedValuestatic URI
uri(String uri)
Creates a URIstatic Map<Class,WriteHandler<?,?>>
writeHandlerMap(Map<Class,WriteHandler<?,?>> customHandlers)
Creates a read-only Map of Class to WriteHandler containing default WriteHandlers with customHandlers merged in.static <T> Writer<T>
writer(TransitFactory.Format type, OutputStream out)
Creates a writer instance.static <T> Writer<T>
writer(TransitFactory.Format type, OutputStream out, WriteHandler<?,?> defaultWriteHandler)
Creates a writer instance.static <T> Writer<T>
writer(TransitFactory.Format type, OutputStream out, Map<Class,WriteHandler<?,?>> customHandlers)
Creates a writer instance.static <T> Writer<T>
writer(TransitFactory.Format type, OutputStream out, Map<Class,WriteHandler<?,?>> customHandlers, WriteHandler<?,?> defaultWriteHandler)
Creates a writer instance.static <T> Writer<T>
writer(TransitFactory.Format type, OutputStream out, Map<Class,WriteHandler<?,?>> customHandlers, WriteHandler<?,?> defaultWriteHandler, Function<Object,Object> transform)
Creates a writer instance.
-
-
-
Method Detail
-
writer
public static <T> Writer<T> writer(TransitFactory.Format type, OutputStream out)
Creates a writer instance.- Parameters:
type
- format to write inout
- output stream to write to- Returns:
- a Writer
-
writer
public static <T> Writer<T> writer(TransitFactory.Format type, OutputStream out, Map<Class,WriteHandler<?,?>> customHandlers)
Creates a writer instance.- Parameters:
type
- format to write inout
- output stream to write tocustomHandlers
- additional WriteHandlers to use in addition to or in place of the default WriteHandlers- Returns:
- a writer
-
writer
public static <T> Writer<T> writer(TransitFactory.Format type, OutputStream out, WriteHandler<?,?> defaultWriteHandler)
Creates a writer instance.- Parameters:
type
- format to write inout
- output stream to write todefaultWriteHandler
- WriteHandler to use by default- Returns:
- a writer
-
writer
public static <T> Writer<T> writer(TransitFactory.Format type, OutputStream out, Map<Class,WriteHandler<?,?>> customHandlers, WriteHandler<?,?> defaultWriteHandler)
Creates a writer instance.- Parameters:
type
- format to write inout
- output stream to write tocustomHandlers
- additional WriteHandlers to use in addition to or in place of the default WriteHandlersdefaultWriteHandler
- WriteHandler to use by default- Returns:
- a writer
-
writer
public static <T> Writer<T> writer(TransitFactory.Format type, OutputStream out, Map<Class,WriteHandler<?,?>> customHandlers, WriteHandler<?,?> defaultWriteHandler, Function<Object,Object> transform)
Creates a writer instance.- Parameters:
type
- format to write inout
- output stream to write tocustomHandlers
- additional WriteHandlers to use in addition to or in place of the default WriteHandlersdefaultWriteHandler
- WriteHandler to use by defaulttransform
- a transform function to apply to values before writing- Returns:
- a writer
-
reader
public static Reader reader(TransitFactory.Format type, InputStream in)
Creates a reader instance.- Parameters:
type
- the format to read inin
- the input stream to read from- Returns:
- a reader
-
reader
public static Reader reader(TransitFactory.Format type, InputStream in, Map<String,ReadHandler<?,?>> customHandlers)
Creates a reader instance.- Parameters:
type
- the format to read inin
- the input stream to read fromcustomHandlers
- a map of custom ReadHandlers to use in addition or in place of the default ReadHandlers- Returns:
- a reader
-
reader
public static Reader reader(TransitFactory.Format type, InputStream in, DefaultReadHandler<?> customDefaultHandler)
Creates a reader instance.- Parameters:
type
- the format to read inin
- the input stream to read fromcustomDefaultHandler
- a DefaultReadHandler to use for processing encoded values for which there is no read handler- Returns:
- a reader
-
reader
public static Reader reader(TransitFactory.Format type, InputStream in, Map<String,ReadHandler<?,?>> customHandlers, DefaultReadHandler<?> customDefaultHandler)
Creates a reader instance.- Parameters:
type
- the format to read inin
- the input stream to read fromcustomHandlers
- a map of custom ReadHandlers to use in addition or in place of the default ReadHandlerscustomDefaultHandler
- a DefaultReadHandler to use for processing encoded values for which there is no read handler- Returns:
- a reader
-
keyword
public static Keyword keyword(Object o)
Converts a string or keyword to a keyword- Parameters:
o
- A string or a keyword- Returns:
- a keyword
-
symbol
public static Symbol symbol(Object o)
Converts a string or a symbol to a symbol- Parameters:
o
- a string or a symbol- Returns:
- a symbol
-
taggedValue
public static <T> TaggedValue<T> taggedValue(String tag, T rep)
Creates a TaggedValue- Parameters:
tag
- tag stringrep
- value representation- Returns:
- a tagged value
-
link
public static Link link(String href, String rel)
Creates a Link- Parameters:
href
- an href valuerel
- a rel value- Returns:
- a link instance
-
link
public static Link link(URI href, String rel)
Creates a Link- Parameters:
href
- an href valuerel
- a rel value- Returns:
- a link instance
-
link
public static Link link(String href, String rel, String name, String prompt, String render)
Creates a Link- Parameters:
href
- an href valuerel
- a rel valuename
- an optional name valueprompt
- an optional prompt valuerender
- an optional render value- Returns:
- a link instance
-
link
public static Link link(URI href, String rel, String name, String prompt, String render)
Creates a Link- Parameters:
href
- an href valuerel
- a rel valuename
- an optional name valueprompt
- an optional prompt valuerender
- an optional render value- Returns:
- a link instance
-
uri
public static URI uri(String uri)
Creates a URI- Parameters:
uri
- a uri string- Returns:
- the URI
-
defaultDefaultReadHandler
public static DefaultReadHandler<TaggedValue<Object>> defaultDefaultReadHandler()
Returns the DefaultReadHandler that is used by default- Returns:
- DefaultReadHandler instance
-
defaultDefaultWriteHandler
public static WriteHandler<?,?> defaultDefaultWriteHandler()
-
defaultReadHandlers
public static Map<String,ReadHandler<?,?>> defaultReadHandlers()
Returns a map of tags to ReadHandlers that is used by default- Returns:
- tag to ReadHandler map
-
readHandlerMap
public static Map<String,ReadHandler<?,?>> readHandlerMap(Map<String,ReadHandler<?,?>> customHandlers)
Creates a read-only Map of String to ReadHandler containing default ReadHandlers with customHandlers merged in. Use this to build the collection of read handlers once, and pass it to repeated calls to TransitFactory.reader. This can be more efficient than repeatedly passing a map of custom handlers to TransitFactory.reader, which then merges them with the default handlers and/or looks them up in a cache each invocation.- Parameters:
customHandlers
- a map of custom ReadHandlers to use in addition or in place of the default ReadHandlers- Returns:
- a ReadHandlerMap
-
defaultWriteHandlers
public static Map<Class,WriteHandler<?,?>> defaultWriteHandlers()
Returns a map of classes to Handlers that is used by default- Returns:
- class to Handler map
-
writeHandlerMap
public static Map<Class,WriteHandler<?,?>> writeHandlerMap(Map<Class,WriteHandler<?,?>> customHandlers)
Creates a read-only Map of Class to WriteHandler containing default WriteHandlers with customHandlers merged in. Use this to build the collection of write handlers once, and pass it to repeated calls to TransitFactory.reader. This can be more efficient than repeatedly passing a map of custom handlers to TransitFactory.writer, which then merges them with the default handlers and/or looks them up in a cache each invocation.- Parameters:
customHandlers
- a map of custom WriteHandler to use in addition or in place of the default WriteHandler- Returns:
- a WriteHandlerMap
-
-