本文整理汇总了Java中permafrost.tundra.io.InputStreamHelper类的典型用法代码示例。如果您正苦于以下问题:Java InputStreamHelper类的具体用法?Java InputStreamHelper怎么用?Java InputStreamHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InputStreamHelper类属于permafrost.tundra.io包,在下文中一共展示了InputStreamHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import permafrost.tundra.io.InputStreamHelper; //导入依赖的package包/类
/**
* Converts a string, byte array or stream to a string, byte array or stream.
*
* @param object The object to be converted.
* @param charset The character set to use.
* @param mode The desired return type of the object.
* @return The converted object.
* @throws IOException If an I/O problem occurs.
*/
public static Object convert(Object object, Charset charset, ObjectConvertMode mode) throws IOException {
if (object == null) return null;
mode = ObjectConvertMode.normalize(mode);
if (mode == ObjectConvertMode.BYTES) {
object = BytesHelper.normalize(object, charset);
} else if (mode == ObjectConvertMode.STRING) {
object = StringHelper.normalize(object, charset);
} else if (mode == ObjectConvertMode.BASE64) {
object = BytesHelper.base64Encode(BytesHelper.normalize(object, charset));
} else if (mode == ObjectConvertMode.STREAM) {
object = InputStreamHelper.normalize(object, charset);
} else {
throw new IllegalArgumentException("Unsupported conversion mode specified: " + mode);
}
return object;
}
示例2: testGetDigestWithBufferedInputStream
import permafrost.tundra.io.InputStreamHelper; //导入依赖的package包/类
@Test
public void testGetDigestWithBufferedInputStream() throws Exception {
File tempFile = FileHelper.create();
FileHelper.writeFromBytes(tempFile, data, false);
Map.Entry<? extends InputStream, byte[]> result = MessageDigestHelper.digest(algorithm, new FileInputStream(tempFile));
assertArrayEquals(sha256, result.getValue());
InputStream inputStream = result.getKey();
assertArrayEquals(data, InputStreamHelper.read(inputStream, false));
inputStream.reset();
assertArrayEquals(data, InputStreamHelper.read(inputStream, false));
inputStream.reset();
assertArrayEquals(data, InputStreamHelper.read(inputStream, false));
inputStream.close();
}
示例3: compress
import permafrost.tundra.io.InputStreamHelper; //导入依赖的package包/类
/**
* Compresses the given contents into a zip archive.
*
* @param contents The contents to be compressed.
* @return The zip archive containing the compressed contents.
* @throws IOException If an I/O exception occurs reading from the streams.
*/
public static InputStream compress(ZipEntryWithData... contents) throws IOException {
if (contents == null) return null;
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ZipOutputStream zipOutputStream = null;
try {
zipOutputStream = new ZipOutputStream(byteArrayOutputStream);
for (int i = 0; i < contents.length; i++) {
if (contents[i] != null) {
String name = contents[i].getName();
if (name == null) name = "Untitled " + (i + 1);
InputStream inputStream = InputStreamHelper.normalize(contents[i].getData());
try {
zipOutputStream.putNextEntry(new ZipEntry(name));
InputOutputHelper.copy(inputStream, zipOutputStream, false);
} finally {
CloseableHelper.close(inputStream);
}
}
}
} finally {
if (zipOutputStream != null) zipOutputStream.closeEntry();
CloseableHelper.close(zipOutputStream);
}
return (InputStream)ObjectHelper.convert(byteArrayOutputStream.toByteArray(), ObjectConvertMode.STREAM);
}
示例4: decompress
import permafrost.tundra.io.InputStreamHelper; //导入依赖的package包/类
/**
* Decompresses the given zip archive.
*
* @param inputStream The zip archive to decompress.
* @return The decompressed contents of the zip archive.
* @throws IOException If an I/O problem occurs while reading from the stream.
*/
public static ZipEntryWithData[] decompress(InputStream inputStream) throws IOException {
if (inputStream == null) return null;
ZipInputStream zipInputStream = null;
List<ZipEntryWithData> contents = new ArrayList<ZipEntryWithData>();
byte[] buffer = new byte[InputOutputHelper.DEFAULT_BUFFER_SIZE];
try {
zipInputStream = new ZipInputStream(InputStreamHelper.normalize(inputStream));
ZipEntry zipEntry;
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
//InputStreamHelper.copy(zipInputStream, byteArrayOutputStream, false);
int count;
while ((count = zipInputStream.read(buffer)) > 0) {
byteArrayOutputStream.write(buffer, 0, count);
}
byteArrayOutputStream.close();
contents.add(new ZipEntryWithData(zipEntry.getName(), byteArrayOutputStream.toByteArray()));
}
} finally {
CloseableHelper.close(zipInputStream);
}
return contents.toArray(new ZipEntryWithData[contents.size()]);
}
示例5: compress
import permafrost.tundra.io.InputStreamHelper; //导入依赖的package包/类
/**
* GZIP compresses the given data.
*
* @param inputStream The data to be compressed.
* @return The compressed data.
* @throws IOException If an I/O problem occurs when reading from the stream.
*/
public static InputStream compress(InputStream inputStream) throws IOException {
if (inputStream == null) return null;
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
InputOutputHelper.copy(InputStreamHelper.normalize(inputStream), new GZIPOutputStream(byteArrayOutputStream));
return InputStreamHelper.normalize(byteArrayOutputStream.toByteArray());
}
示例6: decompress
import permafrost.tundra.io.InputStreamHelper; //导入依赖的package包/类
/**
* GZIP decompresses the given data.
*
* @param inputStream The compressed data to be decompressed.
* @return The decompressed data.
* @throws IOException If an I/O problem occurs when reading from the stream.
*/
public static InputStream decompress(InputStream inputStream) throws IOException {
if (inputStream == null) return null;
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
InputOutputHelper.copy(new GZIPInputStream(InputStreamHelper.normalize(inputStream)), byteArrayOutputStream);
return InputStreamHelper.normalize(byteArrayOutputStream.toByteArray());
}
示例7: getInputValues
import permafrost.tundra.io.InputStreamHelper; //导入依赖的package包/类
/**
* Reads input for service invocation. Turns properly formatted input into an instance of Values
* suitable for service invocation. Called before service invocation to provide input.
*
* @param contentHandlerInput The input arguments for processing by the content handler.
* @throws IOException If an error occurs writing to the output stream.
*/
@Override
public void getInputValues(ContentHandlerInput contentHandlerInput) throws IOException {
if (startable.isStarted()) {
byte[] bytes = InputStreamHelper.read(contentHandlerInput.getInputStream());
if (bytes != null) {
contentHandlerInput.setInputStream(new ByteArrayInputStream(bytes));
InvokeState invokeState = contentHandlerInput.getInvokeState();
String contentType = null;
Charset charset = null;
if (invokeState != null) {
try {
contentType = MIMETypeHelper.normalize(invokeState.getContentType());
} catch (MimeTypeParseException ex) {
// do nothing
}
charset = CharsetHelper.normalize(invokeState.getContentEncoding());
}
if (contentType == null) contentType = MIMETypeHelper.DEFAULT_MIME_TYPE_STRING;
if (charset == null) charset = CharsetHelper.DEFAULT_CHARSET;
String content;
if (TEXT_CONTENT_PATTERN.matcher(contentType).matches()) {
content = JavaEscape.escapeJava(new String(bytes, charset), JavaEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_BASIC_ESCAPE_SET);
} else {
content = BytesHelper.base64Encode(bytes);
}
loggable.log("type = ", contentType, ", content = ", content);
}
}
}
示例8: testGetDigestWithByteArrayInputStream
import permafrost.tundra.io.InputStreamHelper; //导入依赖的package包/类
@Test
public void testGetDigestWithByteArrayInputStream() throws Exception {
Map.Entry<? extends InputStream, byte[]> result = MessageDigestHelper.digest(algorithm, new ByteArrayInputStream(data));
assertArrayEquals(sha256, result.getValue());
InputStream inputStream = result.getKey();
assertArrayEquals(data, InputStreamHelper.read(inputStream, false));
inputStream.reset();
assertArrayEquals(data, InputStreamHelper.read(inputStream, false));
inputStream.reset();
assertArrayEquals(data, InputStreamHelper.read(inputStream, false));
inputStream.close();
}
示例9: testEvaluateXPathCondition
import permafrost.tundra.io.InputStreamHelper; //导入依赖的package包/类
@Test
public void testEvaluateXPathCondition() throws Exception {
String content = "<a><z>1</z><z>2</z><z>3</z><b><c>Example</c></b><b><c><d>Example 2</d></c></b><b></b></a>";
Document document = DocumentHelper.parse(InputSourceHelper.normalize(InputStreamHelper.normalize(content)));
IDataMap scope = new IDataMap();
scope.put("document", document);
assertTrue(ConditionEvaluator.evaluate("%document/a/z[1]% == 1", scope));
assertTrue(ConditionEvaluator.evaluate("%document/a/z[1]% == 1 and %document/a/z[2]% == 2", scope));
assertTrue(ConditionEvaluator.evaluate("%document/a/y% == $null", scope));
assertFalse(ConditionEvaluator.evaluate("%document/a/y% != $null", scope));
assertTrue(ConditionEvaluator.evaluate("%document/a% != $null", scope));
}
示例10: testEvaluateXPathAndBranchCondition
import permafrost.tundra.io.InputStreamHelper; //导入依赖的package包/类
@Test
public void testEvaluateXPathAndBranchCondition() throws Exception {
String content = "<a><z>1</z><z>2</z><z>3</z><b><c>Example</c></b><b><c><d>Example 2</d></c></b><b></b></a>";
Document document = DocumentHelper.parse(InputSourceHelper.normalize(InputStreamHelper.normalize(content)));
IDataMap scope = new IDataMap();
scope.put("document", document);
scope.put("domain", "example.com");
assertTrue(ConditionEvaluator.evaluate("%document/a/z% == 1 and %domain% == \"example.com\"", scope));
}
示例11: testGetAbsoluteXPath
import permafrost.tundra.io.InputStreamHelper; //导入依赖的package包/类
@Test
public void testGetAbsoluteXPath() throws Exception {
String xmldata = "<test><a>1</a><b>2</b></test>";
IDataMap pipeline = new IDataMap();
pipeline.put("node", DocumentHelper.parse(InputSourceHelper.normalize(InputStreamHelper.normalize(xmldata))));
Object value = IDataHelper.get(pipeline, new IDataMap(), "/node/test/a");
assertEquals("1", value);
}
示例12: testGetRelativeXPath
import permafrost.tundra.io.InputStreamHelper; //导入依赖的package包/类
@Test
public void testGetRelativeXPath() throws Exception {
String xmldata = "<test><a>1</a><b>2</b></test>";
IDataMap scope = new IDataMap();
scope.put("node", DocumentHelper.parse(InputSourceHelper.normalize(InputStreamHelper.normalize(xmldata))));
Object value = IDataHelper.get(null, scope, "node/test/a");
assertEquals("1", value);
}
示例13: getContent
import permafrost.tundra.io.InputStreamHelper; //导入依赖的package包/类
/**
* Returns the content associated with the given content part name from the given BizDocEnvelope as an InputStream.
*
* @param document The BizDocEnvelope whose content is to be returned.
* @param contentPart The content part name whose content is to be returned.
* @return The BizDocEnvelope content associated with the given part name as an InputStream.
* @throws ServiceException If an IO error occurs.
*/
public static InputStream getContent(BizDocEnvelope document, BizDocContentPart contentPart) throws ServiceException {
if (document == null || contentPart == null) return null;
InputStream content = null;
try {
content = InputStreamHelper.normalize(contentPart.getContent(document.getInternalId()));
} catch (IOException ex) {
ExceptionHelper.raise(ex);
}
return content;
}
示例14: testSortWithMultipleKeys
import permafrost.tundra.io.InputStreamHelper; //导入依赖的package包/类
@Test
public void testSortWithMultipleKeys() throws Exception {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"\n" +
"<IDataXMLCoder version=\"1.0\">\n" +
" <record javaclass=\"com.wm.data.ISMemDataImpl\">\n" +
" <array name=\"array\" type=\"record\" depth=\"1\">\n" +
" <record javaclass=\"com.wm.util.Values\">\n" +
" <value name=\"string\">a</value>\n" +
" <value name=\"integer\">26</value>\n" +
" <value name=\"decimal\">43.2</value>\n" +
" <value name=\"datetime\">02-03-2015</value>\n" +
" <value name=\"duration\">P1Y</value>\n" +
" </record>\n" +
" <record javaclass=\"com.wm.util.Values\">\n" +
" <value name=\"string\">z</value>\n" +
" <value name=\"integer\">99</value>\n" +
" <value name=\"decimal\">99.9</value>\n" +
" <value name=\"datetime\">01-01-2014</value>\n" +
" <value name=\"duration\">P1D</value>\n" +
" </record>\n" +
" <record javaclass=\"com.wm.util.Values\">\n" +
" <value name=\"string\">a</value>\n" +
" <value name=\"integer\">25</value>\n" +
" <value name=\"decimal\">64.345</value>\n" +
" <value name=\"datetime\">01-01-2014</value>\n" +
" <value name=\"duration\">PT1S</value>\n" +
" </record>\n" +
" </array>\n" +
" </record>\n" +
"</IDataXMLCoder>\n";
IDataMap map = new IDataMap(IDataXMLParser.getInstance().parse(InputStreamHelper.normalize(xml)));
IData[] array = (IData[])map.get("array");
IDataComparisonCriterion c1 = new IDataComparisonCriterion("string", "string", false);
IDataComparisonCriterion c2 = new IDataComparisonCriterion("integer", "integer", false);
IData[] result = IDataHelper.sort(array, c1, c2);
assertEquals(3, result.length);
IDataMap first = new IDataMap(result[0]);
assertEquals("a", first.get("string"));
assertEquals("25", first.get("integer"));
IDataMap second = new IDataMap(result[1]);
assertEquals("a", second.get("string"));
assertEquals("26", second.get("integer"));
IDataMap third = new IDataMap(result[2]);
assertEquals("z", third.get("string"));
assertEquals("99", third.get("integer"));
}
示例15: setUp
import permafrost.tundra.io.InputStreamHelper; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
String content = "<a><z>1</z><z>2</z><z>3</z><b><c>Example</c></b><b><c><d>Example 2</d></c></b><b></b></a>";
document = DocumentHelper.parse(InputSourceHelper.normalize(InputStreamHelper.normalize(content)));
}