本文整理汇总了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;
}
示例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);
}
示例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()]);
}
示例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());
}
示例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());
}
示例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;
}
示例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));
}
示例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"))));
}
示例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));
}
示例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));
}