use of permafrost.tundra.lang.ObjectConvertMode in project Tundra by Permafrost.
the class file method read.
public static final void read(IData pipeline) throws ServiceException {
// --- <<IS-START(read)>> ---
// @subtype unknown
// @sigtype java 3.5
// [i] field:0:required $file
// [i] field:0:optional $mode {"stream","bytes","string"}
// [i] field:0:optional $encoding
// [o] object:0:required $content
IDataCursor cursor = pipeline.getCursor();
try {
String file = IDataHelper.get(cursor, "$file", String.class);
Charset charset = IDataHelper.get(cursor, "$encoding", Charset.class);
ObjectConvertMode mode = IDataHelper.get(cursor, "$mode", ObjectConvertMode.class);
IDataHelper.put(cursor, "$content", ObjectHelper.convert(FileHelper.readToBytes(file), charset, mode));
} catch (IOException ex) {
ExceptionHelper.raise(ex);
} finally {
cursor.destroy();
}
// --- <<IS-END>> ---
}
use of permafrost.tundra.lang.ObjectConvertMode in project Tundra by Permafrost.
the class gzip method compress.
// ---( server methods )---
public static final void compress(IData pipeline) throws ServiceException {
// --- <<IS-START(compress)>> ---
// @subtype unknown
// @sigtype java 3.5
// [i] object:0:optional $content
// [i] field:0:optional $encoding
// [i] field:0:optional $mode {"stream","bytes","string","base64"}
// [o] object:0:optional $content.gzip
IDataCursor cursor = pipeline.getCursor();
try {
Object input = IDataHelper.get(cursor, "$content");
Charset charset = IDataHelper.get(cursor, "$encoding", Charset.class);
ObjectConvertMode mode = IDataHelper.get(cursor, "$mode", ObjectConvertMode.class);
Object output = ObjectHelper.convert(GzipHelper.compress(InputStreamHelper.normalize(input, charset)), charset, mode);
IDataHelper.put(cursor, "$content.gzip", output, false);
} catch (IOException ex) {
ExceptionHelper.raise(ex);
} finally {
cursor.destroy();
}
// --- <<IS-END>> ---
}
use of permafrost.tundra.lang.ObjectConvertMode in project Tundra by Permafrost.
the class html method emit.
public static final void emit(IData pipeline) throws ServiceException {
// --- <<IS-START(emit)>> ---
// @subtype unknown
// @sigtype java 3.5
// [i] record:0:optional $document
// [i] field:0:optional $encoding
// [i] field:0:optional $depth
// [i] field:0:optional $mode {"stream","bytes","string"}
// [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);
int depth = IDataHelper.getOrDefault(cursor, "$depth", Integer.class, Integer.MAX_VALUE);
ObjectConvertMode mode = IDataHelper.get(cursor, "$mode", ObjectConvertMode.class);
if (document != null) {
IDataHelper.put(cursor, "$content", ObjectHelper.convert(IDataHTMLParser.getInstance().encodeToString(document, depth), charset, mode), false);
}
} catch (IOException ex) {
ExceptionHelper.raise(ex);
} finally {
cursor.destroy();
}
// --- <<IS-END>> ---
}
use of permafrost.tundra.lang.ObjectConvertMode in project Tundra by Permafrost.
the class content method digest.
// ---( server methods )---
public static final void digest(IData pipeline) throws ServiceException {
// --- <<IS-START(digest)>> ---
// @subtype unknown
// @sigtype java 3.5
// [i] object:0:optional $content
// [i] field:0:optional $encoding
// [i] field:0:optional $algorithm {"SHA-512","SHA-384","SHA-256","SHA","MD5","MD2"}
// [i] field:0:optional $mode {"stream","bytes","base64"}
// [o] object:0:optional $content
// [o] object:0:optional $digest
IDataCursor cursor = pipeline.getCursor();
try {
Object content = IDataHelper.get(cursor, "$content");
Charset charset = IDataHelper.get(cursor, "$encoding", Charset.class);
MessageDigest algorithm = IDataHelper.getOrDefault(cursor, "$algorithm", MessageDigest.class, MessageDigestHelper.DEFAULT_ALGORITHM);
ObjectConvertMode mode = IDataHelper.get(cursor, "$mode", ObjectConvertMode.class);
if (content != null) {
Map.Entry<? extends Object, byte[]> digest = MessageDigestHelper.digest(algorithm, content, charset);
if (digest != null) {
IDataHelper.put(cursor, "$content", digest.getKey());
IDataHelper.put(cursor, "$digest", ObjectHelper.convert(digest.getValue(), mode));
}
}
} catch (IOException ex) {
ExceptionHelper.raise(ex);
} catch (NoSuchAlgorithmException ex) {
ExceptionHelper.raise(ex);
} finally {
cursor.destroy();
}
// --- <<IS-END>> ---
}
use of permafrost.tundra.lang.ObjectConvertMode in project Tundra by Permafrost.
the class xml method minify.
public static final void minify(IData pipeline) throws ServiceException {
// --- <<IS-START(minify)>> ---
// @subtype unknown
// @sigtype java 3.5
// [i] object:0:optional $content
// [i] field:0:optional $encoding
// [i] field:0:optional $mode {"stream","bytes","string"}
// [o] object:0:optional $content.minified
IDataCursor cursor = pipeline.getCursor();
try {
Object content = IDataHelper.get(cursor, "$content");
Charset charset = IDataHelper.get(cursor, "$encoding", Charset.class);
ObjectConvertMode mode = IDataHelper.get(cursor, "$mode", ObjectConvertMode.class);
IDataHelper.put(cursor, "$content.minified", ObjectHelper.convert(XMLMinificationHelper.minify(InputStreamHelper.normalize(content, charset)), charset, mode), false);
} catch (IOException ex) {
ExceptionHelper.raise(ex);
} finally {
cursor.destroy();
}
// --- <<IS-END>> ---
}
Aggregations