当前位置: 首页>>代码示例>>Java>>正文


Java InputStreamHelper.normalize方法代码示例

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


在下文中一共展示了InputStreamHelper.normalize方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: valueOf

import permafrost.tundra.io.InputStreamHelper; //导入方法依赖的package包/类
/**
 * Returns a new ZipEntryWithData object given an IData document.
 *
 * @param document The IData document to construct the ZipEntryWithData object from; must include the following
 *                 keys: name, encoding, content.
 * @return The ZipEntryWithData object representing the given IData document.
 * @throws IOException If an I/O problem occurs reading from a stream.
 */
public static ZipEntryWithData valueOf(IData document) throws IOException {
    if (document == null) return null;
    IDataMap map = IDataMap.of(document);
    return new ZipEntryWithData((String)map.get("name"), InputStreamHelper.normalize(map.get("content"), CharsetHelper.normalize((String)map.get("encoding"))));
}
 
开发者ID:Permafrost,项目名称:Tundra.java,代码行数:14,代码来源:ZipEntryWithData.java

示例9: convert

import permafrost.tundra.io.InputStreamHelper; //导入方法依赖的package包/类
/**
 * Returns a new InputStream by converting the given InputStream from the input charset to the output charset,
 * unless the two charsets are equal in which case the given InputStream is returned as is.
 *
 * @param content    The text content to be converted to another charset.
 * @param inCharset  The charset the text content is currently encoded with.
 * @param outCharset The charset the returned converted text content will be encoded with.
 * @return The given text content converted from one charset to another.
 * @throws IOException If an I/O error occurs.
 */
public static InputStream convert(InputStream content, Charset inCharset, Charset outCharset) throws IOException {
    return InputStreamHelper.normalize(convert(BytesHelper.normalize(content), inCharset, outCharset));
}
 
开发者ID:Permafrost,项目名称:Tundra.java,代码行数:14,代码来源:CharsetHelper.java

示例10: canonicalize

import permafrost.tundra.io.InputStreamHelper; //导入方法依赖的package包/类
/**
 * Canonicalizes the given XML content using the given algorithm.
 *
 * @param input             The XML content to canonicalize.
 * @param charset           The character set the XML content is encoded with.
 * @param algorithm         The canonicalization algorithm to use.
 * @return                  The given XML content canonicalized with the specified algorithm.
 * @throws ServiceException If a canonicalization error occurs.
 * @throws IOException      If an I/O error occurs.
 */
public static InputStream canonicalize(InputStream input, Charset charset, XMLCanonicalizationAlgorithm algorithm) throws ServiceException, IOException {
    return InputStreamHelper.normalize(canonicalize(BytesHelper.normalize(input), charset, algorithm));
}
 
开发者ID:Permafrost,项目名称:TundraXML.java,代码行数:14,代码来源:XMLCanonicalizationHelper.java


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