• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java InputStreamHelper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中permafrost.tundra.io.InputStreamHelper的典型用法代码示例。如果您正苦于以下问题:Java InputStreamHelper类的具体用法?Java InputStreamHelper怎么用?Java InputStreamHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



InputStreamHelper类属于permafrost.tundra.io包,在下文中一共展示了InputStreamHelper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
 
开发者ID:Permafrost,项目名称:Tundra.java,代码行数:29,代码来源:ObjectHelper.java


示例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();
}
 
开发者ID:Permafrost,项目名称:Tundra.java,代码行数:19,代码来源:MessageDigestHelperTest.java


示例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);
}
 
开发者ID:Permafrost,项目名称:Tundra.java,代码行数:38,代码来源:ZipHelper.java


示例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()]);
}
 
开发者ID:Permafrost,项目名称:Tundra.java,代码行数:36,代码来源:ZipHelper.java


示例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());
}
 
开发者ID:Permafrost,项目名称:Tundra.java,代码行数:16,代码来源:GzipHelper.java


示例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());
}
 
开发者ID:Permafrost,项目名称:Tundra.java,代码行数:16,代码来源:GzipHelper.java


示例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);
        }
    }
}
 
开发者ID:Permafrost,项目名称:Tundra.java,代码行数:41,代码来源:LoggingContentHandler.java


示例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();
}
 
开发者ID:Permafrost,项目名称:Tundra.java,代码行数:16,代码来源:MessageDigestHelperTest.java


示例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));
}
 
开发者ID:Permafrost,项目名称:Tundra.java,代码行数:15,代码来源:ConditionEvaluatorTest.java


示例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));
}
 
开发者ID:Permafrost,项目名称:Tundra.java,代码行数:12,代码来源:ConditionEvaluatorTest.java


示例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);
}
 
开发者ID:Permafrost,项目名称:Tundra.java,代码行数:12,代码来源:IDataHelperTest.java


示例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);
}
 
开发者ID:Permafrost,项目名称:Tundra.java,代码行数:12,代码来源:IDataHelperTest.java


示例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;
}
 
开发者ID:Permafrost,项目名称:TundraTN.java,代码行数:22,代码来源:BizDocContentHelper.java


示例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"));
}
 
开发者ID:Permafrost,项目名称:Tundra.java,代码行数:54,代码来源:IDataHelperTest.java


示例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)));
}
 
开发者ID:Permafrost,项目名称:Tundra.java,代码行数:7,代码来源:XPathHelperTest.java


示例16: digest

import permafrost.tundra.io.InputStreamHelper; //导入依赖的package包/类
/**
 * Calculates a message digest for the given data using the given algorithm.
 *
 * @param algorithm                 The algorithm to use when calculating the message digest.
 * @param data                      The data to calculate the digest for.
 * @return                          The message digest calculated for the given data using the given algorithm.
 * @throws IOException              If an I/O exception occurs reading from the stream.
 * @throws NoSuchAlgorithmException If there is no provider for the default algorithm.
 */
public static Map.Entry<ByteArrayInputStream, byte[]> digest(MessageDigest algorithm, ByteArrayInputStream data) throws IOException, NoSuchAlgorithmException {
    if (data == null) return null;

    byte[] bytes = InputStreamHelper.read(data, false);
    data.reset();

    return new AbstractMap.SimpleImmutableEntry<ByteArrayInputStream, byte[]>(data, digest(algorithm, bytes));
}
 
开发者ID:Permafrost,项目名称:Tundra.java,代码行数:18,代码来源:MessageDigestHelper.java


示例17: normalize

import permafrost.tundra.io.InputStreamHelper; //导入依赖的package包/类
/**
 * Converts the given java.io.InputStream as a String, and closes the stream.
 *
 * @param inputStream A java.io.InputStream to be converted to a string.
 * @param charset     The character set to use.
 * @return A string representation of the given java.io.InputStream.
 * @throws IOException If there is an error reading from the java.io.InputStream.
 */
public static String normalize(InputStream inputStream, Charset charset) throws IOException {
    if (inputStream == null) return null;

    Writer writer = new StringWriter();
    InputOutputHelper.copy(new InputStreamReader(InputStreamHelper.normalize(inputStream), CharsetHelper.normalize(charset)), writer);
    return writer.toString();
}
 
开发者ID:Permafrost,项目名称:Tundra.java,代码行数:16,代码来源:StringHelper.java


示例18: minify

import permafrost.tundra.io.InputStreamHelper; //导入依赖的package包/类
/**
 * Removes extraneous whitespace and comments from the given XML content.
 *
 * @param content               The XML content to be minified.
 * @param charset               The character set the character data is encoded with.
 * @param removeComments        Whether XML comments should be removed as part of the minification.
 * @param removeInterTagSpaces  Whether whitespace between tags should be removed as part of the minification.
 * @return                      The minified XML content.
 * @throws IOException
 */
public static InputStream minify(InputStream content, Charset charset, boolean removeComments, boolean removeInterTagSpaces) throws IOException {
    if (content == null) return null;

    XmlCompressor compressor = new XmlCompressor();
    compressor.setRemoveComments(removeComments);
    compressor.setRemoveIntertagSpaces(removeInterTagSpaces);

    return InputStreamHelper.normalize(compressor.compress(StringHelper.normalize(content, CharsetHelper.normalize(charset))), CharsetHelper.normalize(charset));
}
 
开发者ID:Permafrost,项目名称:TundraXML.java,代码行数:20,代码来源:XMLMinificationHelper.java


示例19: encode

import permafrost.tundra.io.InputStreamHelper; //导入依赖的package包/类
/**
 * Encodes the given IData document as HTML to the given output stream.
 *
 * @param outputStream The stream to write the encoded IData to.
 * @param document     The IData document to be encoded.
 * @param charset      The character set to use.
 * @throws IOException If there is a problem writing to the stream.
 */
public void encode(OutputStream outputStream, IData document, Charset charset) throws IOException {
    InputOutputHelper.copy(InputStreamHelper.normalize(encodeToString(document), charset), outputStream);
}
 
开发者ID:Permafrost,项目名称:TundraHTML.java,代码行数:12,代码来源:IDataHTMLParser.java


示例20: encode

import permafrost.tundra.io.InputStreamHelper; //导入依赖的package包/类
/**
 * Encodes the given IData document as CSV to the given output stream.
 *
 * @param outputStream The stream to write the encoded IData to.
 * @param document     The IData document to be encoded.
 * @param charset      The character set to use.
 * @throws IOException If there is a problem writing to the stream.
 */
@Override
public void encode(OutputStream outputStream, IData document, Charset charset) throws IOException {
    InputOutputHelper.copy(InputStreamHelper.normalize(encodeToString(document), charset), outputStream);
}
 
开发者ID:Permafrost,项目名称:TundraCSV.java,代码行数:13,代码来源:IDataCSVParser.java



注:本文中的permafrost.tundra.io.InputStreamHelper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DataSender类代码示例发布时间:2022-05-23
下一篇:
Java DefaultRealMatrixChangingVisitor类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap