T
- The Java type to marshall as CSV.@Supports(value="text/csv") public abstract class AbstractCSVWriter<T> extends Object implements Writer<T>
Writer
.
It provides you a CSVPrinter
to manage the marshalling.Modifier and Type | Field and Description |
---|---|
protected RenderingContext |
ctx
The current
RenderingContext . |
protected MarshallerRegistry |
registry |
protected SchemaManager |
schemaManager |
static String |
TEXT_CSV |
static javax.ws.rs.core.MediaType |
TEXT_CSV_TYPE |
Constructor and Description |
---|
AbstractCSVWriter() |
Modifier and Type | Method and Description |
---|---|
boolean |
accept(Class<?> clazz,
Type genericType,
javax.ws.rs.core.MediaType mediatype)
Checks if this marshaller can handle the marshalling request.
|
protected org.apache.commons.csv.CSVPrinter |
getCSVPrinter(T entity,
OutputStream out) |
protected void |
printCalendar(Calendar value,
org.apache.commons.csv.CSVPrinter printer) |
void |
write(T entity,
Class<?> clazz,
Type genericType,
javax.ws.rs.core.MediaType mediatype,
OutputStream out)
Writes the entity to out
OutputStream using mediatype format. |
protected abstract void |
write(T entity,
org.apache.commons.csv.CSVPrinter printer) |
protected abstract void |
writeHeader(T entity,
org.apache.commons.csv.CSVPrinter printer) |
public static final String TEXT_CSV
public static final javax.ws.rs.core.MediaType TEXT_CSV_TYPE
@Inject protected RenderingContext ctx
RenderingContext
.@Inject protected SchemaManager schemaManager
@Inject protected MarshallerRegistry registry
public AbstractCSVWriter()
public boolean accept(Class<?> clazz, Type genericType, javax.ws.rs.core.MediaType mediatype)
Marshaller
Please note it's useless to check that clazz is an instance of EntityType or if generic type and entity type are
compatible (unlike JAX-RS which just checks the clazz, not the generic type). It's also useless to check
Supports
is compatible with mediatype. This is already done by the MarshallerRegistry
This method implementation can use injected properties. So you can check the current RenderingContext
to
accept or reject a marshalling request.
accept
in interface Marshaller<T>
clazz
- The type to marshall.genericType
- The generic type to marshall.mediatype
- The managed mimetype.public void write(T entity, Class<?> clazz, Type genericType, javax.ws.rs.core.MediaType mediatype, OutputStream out) throws IOException
Writer
OutputStream
using mediatype format.
This method implementation can use injected properties.
write
in interface Writer<T>
entity
- The entity to marshall.clazz
- The requested marshalled class.genericType
- The requested marshalled generic type.mediatype
- The target mediatype.out
- The output of this marshaller.IOException
- If some error append while writing entity to out.protected abstract void write(T entity, org.apache.commons.csv.CSVPrinter printer) throws IOException
IOException
protected abstract void writeHeader(T entity, org.apache.commons.csv.CSVPrinter printer) throws IOException
IOException
protected org.apache.commons.csv.CSVPrinter getCSVPrinter(T entity, OutputStream out) throws IOException
IOException
protected void printCalendar(Calendar value, org.apache.commons.csv.CSVPrinter printer) throws IOException
IOException
Copyright © 2019 Nuxeo. All rights reserved.