use of java.nio.charset.Charset in project Tundra by Permafrost.
the class zip method decompress.
public static final void decompress(IData pipeline) throws ServiceException {
// --- <<IS-START(decompress)>> ---
// @subtype unknown
// @sigtype java 3.5
// [i] object:0:optional $contents.zip
// [i] field:0:optional $encoding
// [i] field:0:optional $mode {"stream","bytes","string","base64"}
// [o] record:1:optional $contents
// [o] - field:0:required name
// [o] - object:0:required content
IDataCursor cursor = pipeline.getCursor();
try {
Object input = IDataHelper.get(cursor, "$contents.zip");
Charset charset = IDataHelper.get(cursor, "$encoding", Charset.class);
ObjectConvertMode mode = IDataHelper.get(cursor, "$mode", ObjectConvertMode.class);
ZipEntryWithData[] entries = ZipHelper.decompress(InputStreamHelper.normalize(input, charset));
IDataHelper.put(cursor, "$contents", ZipEntryWithData.toIDataArray(entries, charset, mode), false);
} catch (IOException ex) {
ExceptionHelper.raise(ex);
} finally {
cursor.destroy();
}
// --- <<IS-END>> ---
}
use of java.nio.charset.Charset in project Tundra by Permafrost.
the class json method emit.
// ---( server methods )---
public static final void emit(IData pipeline) throws ServiceException {
// --- <<IS-START(emit)>> ---
// @subtype unknown
// @sigtype java 3.5
// [i] record:0:optional $document
// [i] - object:1:optional recordWithNoID
// [i] field:0:optional $encoding
// [i] field:0:optional $mode {"stream","bytes","string"}
// [i] field:0:optional $minify? {"false","true"}
// [o] object:0:optional $content
IDataCursor cursor = pipeline.getCursor();
try {
IData document = IDataHelper.get(cursor, "$document", IData.class);
Charset charset = IDataHelper.get(cursor, "$encoding", Charset.class);
ObjectConvertMode mode = IDataHelper.get(cursor, "$mode", ObjectConvertMode.class);
boolean minify = IDataHelper.getOrDefault(cursor, "$minify?", Boolean.class, false);
if (document != null) {
IDataJSONParser parser = minify ? new IDataJSONParser(!minify) : IDataJSONParser.getInstance();
IDataHelper.put(cursor, "$content", ObjectHelper.convert(parser.emit(document, charset), charset, mode));
}
} catch (IOException ex) {
ExceptionHelper.raise(ex);
} finally {
cursor.destroy();
}
// --- <<IS-END>> ---
}
use of java.nio.charset.Charset in project Tundra by Permafrost.
the class service method respond.
public static final void respond(IData pipeline) throws ServiceException {
// --- <<IS-START(respond)>> ---
// @subtype unknown
// @sigtype java 3.5
// [i] field:0:required $code
// [i] field:0:optional $message
// [i] record:0:optional $headers
// [i] object:0:optional $content
// [i] field:0:optional $content.type
// [i] field:0:optional $encoding
IDataCursor cursor = pipeline.getCursor();
try {
int code = IDataHelper.get(cursor, "$code", Integer.class);
String message = IDataHelper.get(cursor, "$message", String.class);
IData headers = IDataHelper.get(cursor, "$headers", IData.class);
Object content = IDataHelper.get(cursor, "$content");
String contentType = IDataHelper.get(cursor, "$content.type", String.class);
Charset charset = IDataHelper.get(cursor, "$encoding", Charset.class);
ServiceHelper.respond(code, message, headers, InputStreamHelper.normalize(content, charset), contentType, charset);
} finally {
cursor.destroy();
}
// --- <<IS-END>> ---
}
use of java.nio.charset.Charset in project Tundra by Permafrost.
the class xpath method get.
public static final void get(IData pipeline) throws ServiceException {
// --- <<IS-START(get)>> ---
// @subtype unknown
// @sigtype java 3.5
// [i] object:0:optional $content
// [i] field:0:optional $encoding
// [i] field:0:required $expression
// [i] record:0:optional $namespace
// [i] - field:0:optional default
// [i] field:0:optional $recurse? {"false","true"}
// [o] record:1:optional $nodes
// [o] - object:0:required node
// [o] - field:0:required name.qualified
// [o] - field:0:optional name.local
// [o] - field:0:optional name.prefix
// [o] - field:0:optional name.uri
// [o] - field:0:required type
// [o] - field:0:optional value
// [o] - record:1:optional attributes
// [o] -- object:0:required node
// [o] -- field:0:required name.qualified
// [o] -- field:0:optional name.local
// [o] -- field:0:optional name.prefix
// [o] -- field:0:optional name.uri
// [o] -- field:0:required type
// [o] -- field:0:optional value
// [o] - record:1:optional elements
// [o] -- object:0:required node
// [o] -- field:0:required name.qualified
// [o] -- field:0:optional name.local
// [o] -- field:0:optional name.prefix
// [o] -- field:0:optional name.uri
// [o] -- field:0:required type
// [o] -- field:0:optional value
// [o] field:0:required $nodes.length
IDataCursor cursor = pipeline.getCursor();
try {
Object content = IDataHelper.get(cursor, "$content");
Charset charset = IDataHelper.get(cursor, "$encoding", Charset.class);
String expression = IDataHelper.get(cursor, "$expression", String.class);
NamespaceContext namespace = IDataHelper.get(cursor, "$namespace", IDataNamespaceContext.class);
boolean recurse = IDataHelper.getOrDefault(cursor, "$recurse?", Boolean.class, false);
XPathExpression compiledExpression = XPathHelper.compile(expression, namespace);
Node node = null;
if (content instanceof Node) {
node = (Node) content;
} else if (content instanceof InputSource) {
node = DocumentHelper.parse((InputSource) content, namespace);
} else if (content != null) {
node = DocumentHelper.parse(InputStreamHelper.normalize(content, charset), charset, true, namespace);
}
Nodes nodes = XPathHelper.get(node, compiledExpression);
if (nodes != null) {
IDataHelper.put(cursor, "$nodes", nodes.reflect(namespace, recurse));
IDataHelper.put(cursor, "$nodes.length", nodes.size(), String.class);
} else {
IDataHelper.put(cursor, "$nodes.length", "0");
}
} catch (XPathExpressionException ex) {
ExceptionHelper.raise(ex);
} finally {
cursor.destroy();
}
// --- <<IS-END>> ---
}
use of java.nio.charset.Charset in project Tundra by Permafrost.
the class gzip method decompress.
public static final void decompress(IData pipeline) throws ServiceException {
// --- <<IS-START(decompress)>> ---
// @subtype unknown
// @sigtype java 3.5
// [i] object:0:optional $content.gzip
// [i] field:0:optional $encoding
// [i] field:0:optional $mode {"stream","bytes","string","base64"}
// [o] object:0:optional $content
IDataCursor cursor = pipeline.getCursor();
try {
Object input = IDataHelper.get(cursor, "$content.gzip");
Charset charset = IDataHelper.get(cursor, "$encoding", Charset.class);
ObjectConvertMode mode = IDataHelper.get(cursor, "$mode", ObjectConvertMode.class);
Object output = ObjectHelper.convert(GzipHelper.decompress(InputStreamHelper.normalize(input, charset)), charset, mode);
IDataHelper.put(cursor, "$content", output, false);
} catch (IOException ex) {
ExceptionHelper.raise(ex);
} finally {
cursor.destroy();
}
// --- <<IS-END>> ---
}
Aggregations