use of java.io.SequenceInputStream in project Java-Tutorial by gpcodervn.
the class SequenceInputStreamExample method main.
public static void main(String[] args) throws Exception {
FileInputStream input1 = null;
FileInputStream input2 = null;
SequenceInputStream inst = null;
try {
input1 = new FileInputStream("data/test1.txt");
input2 = new FileInputStream("data/test2.txt");
inst = new SequenceInputStream(input1, input2);
int j;
while ((j = inst.read()) != -1) {
System.out.print((char) j);
}
} catch (IOException ex) {
ex.printStackTrace();
} finally {
inst.close();
input1.close();
input2.close();
}
}
use of java.io.SequenceInputStream in project pdfbox by apache.
the class JBIG2Filter method decode.
@Override
public DecodeResult decode(InputStream encoded, OutputStream decoded, COSDictionary parameters, int index, DecodeOptions options) throws IOException {
ImageReader reader = findImageReader("JBIG2", "jbig2-imageio is not installed");
if (reader.getClass().getName().contains("levigo")) {
logLevigoDonated();
}
int bits = parameters.getInt(COSName.BITS_PER_COMPONENT, 1);
COSDictionary params = getDecodeParams(parameters, index);
ImageReadParam irp = reader.getDefaultReadParam();
irp.setSourceSubsampling(options.getSubsamplingX(), options.getSubsamplingY(), options.getSubsamplingOffsetX(), options.getSubsamplingOffsetY());
irp.setSourceRegion(options.getSourceRegion());
options.setFilterSubsampled(true);
InputStream source = encoded;
if (params != null) {
COSBase globals = params.getDictionaryObject(COSName.JBIG2_GLOBALS);
if (globals instanceof COSStream) {
source = new SequenceInputStream(((COSStream) globals).createInputStream(), encoded);
}
}
try (ImageInputStream iis = ImageIO.createImageInputStream(source)) {
reader.setInput(iis);
BufferedImage image;
try {
image = reader.read(0, irp);
} catch (Exception e) {
// wrap and rethrow any exceptions
throw new IOException("Could not read JBIG2 image", e);
}
// depending on your renderer this might or might be needed
if (image.getColorModel().getPixelSize() != bits) {
if (bits != 1) {
LOG.warn("Attempting to handle a JBIG2 with more than 1-bit depth");
}
BufferedImage packedImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_BINARY);
Graphics graphics = packedImage.getGraphics();
graphics.drawImage(image, 0, 0, null);
graphics.dispose();
image = packedImage;
}
DataBuffer dBuf = image.getData().getDataBuffer();
if (dBuf.getDataType() == DataBuffer.TYPE_BYTE) {
decoded.write(((DataBufferByte) dBuf).getData());
} else {
throw new IOException("Unexpected image buffer type");
}
} finally {
reader.dispose();
}
return new DecodeResult(parameters);
}
use of java.io.SequenceInputStream in project fdroidclient by f-droid.
the class ZioEntry method getInputStream.
// Returns an input stream for reading the entry's data.
public InputStream getInputStream(OutputStream monitorStream) throws IOException {
if (entryOut != null) {
entryOut.close();
size = entryOut.getSize();
data = ((ByteArrayOutputStream) entryOut.getWrappedStream()).toByteArray();
compressedSize = data.length;
crc32 = entryOut.getCRC();
entryOut = null;
InputStream rawis = new ByteArrayInputStream(data);
if (compression == 0)
return rawis;
else {
// This extra dummy byte is required by InflaterInputStream when the data doesn't have the header and crc fields (as it is in zip files).
return new InflaterInputStream(new SequenceInputStream(rawis, new ByteArrayInputStream(new byte[1])), new Inflater(true));
}
}
ZioEntryInputStream dataStream;
dataStream = new ZioEntryInputStream(this);
if (monitorStream != null)
dataStream.setMonitorStream(monitorStream);
if (compression != 0) {
// Note: When using nowrap=true with Inflater it is also necessary to provide
// an extra "dummy" byte as input. This is required by the ZLIB native library
// in order to support certain optimizations.
dataStream.setReturnDummyByte(true);
return new InflaterInputStream(dataStream, new Inflater(true));
} else
return dataStream;
}
use of java.io.SequenceInputStream in project quick-media by liuyueyi.
the class PNGImage method parse_IEND_chunk.
private void parse_IEND_chunk(PNGChunk chunk) throws Exception {
// Store text strings
int textLen = textKeys.size();
String[] textArray = new String[2 * textLen];
for (int i = 0; i < textLen; i++) {
String key = (String) textKeys.get(i);
String val = (String) textStrings.get(i);
textArray[2 * i] = key;
textArray[2 * i + 1] = val;
if (emitProperties) {
String uniqueKey = "text_" + i + ':' + key;
properties.put(uniqueKey.toLowerCase(), val);
}
}
if (encodeParam != null) {
encodeParam.setText(textArray);
}
// Store compressed text strings
int ztextLen = ztextKeys.size();
String[] ztextArray = new String[2 * ztextLen];
for (int i = 0; i < ztextLen; i++) {
String key = (String) ztextKeys.get(i);
String val = (String) ztextStrings.get(i);
ztextArray[2 * i] = key;
ztextArray[2 * i + 1] = val;
if (emitProperties) {
String uniqueKey = "ztext_" + i + ':' + key;
properties.put(uniqueKey.toLowerCase(), val);
}
}
if (encodeParam != null) {
encodeParam.setCompressedText(ztextArray);
}
// Parse prior IDAT chunks
InputStream seqStream = new SequenceInputStream(Collections.enumeration(streamVec));
InputStream infStream = new InflaterInputStream(seqStream, new Inflater());
dataStream = new DataInputStream(infStream);
// Create an empty WritableRaster
int depth = bitDepth;
if ((colorType == PNG_COLOR_GRAY) && (bitDepth < 8) && output8BitGray) {
depth = 8;
}
if ((colorType == PNG_COLOR_PALETTE) && expandPalette) {
depth = 8;
}
int bytesPerRow = (outputBands * width * depth + 7) / 8;
int scanlineStride = (depth == 16) ? (bytesPerRow / 2) : bytesPerRow;
theTile = createRaster(width, height, outputBands, scanlineStride, depth);
if (performGammaCorrection && (gammaLut == null)) {
initGammaLut(bitDepth);
}
if ((postProcess == POST_GRAY_LUT) || (postProcess == POST_GRAY_LUT_ADD_TRANS) || (postProcess == POST_GRAY_LUT_ADD_TRANS_EXP)) {
initGrayLut(bitDepth);
}
decodeImage(interlaceMethod == 1);
sampleModel = theTile.getSampleModel();
if ((colorType == PNG_COLOR_PALETTE) && !expandPalette) {
if (outputHasAlphaPalette) {
colorModel = new IndexColorModel(bitDepth, paletteEntries, redPalette, greenPalette, bluePalette, alphaPalette);
} else {
colorModel = new IndexColorModel(bitDepth, paletteEntries, redPalette, greenPalette, bluePalette);
}
} else if ((colorType == PNG_COLOR_GRAY) && (bitDepth < 8) && !output8BitGray) {
byte[] palette = expandBits[bitDepth];
colorModel = new IndexColorModel(bitDepth, palette.length, palette, palette, palette);
} else {
colorModel = createComponentColorModel(sampleModel);
}
}
use of java.io.SequenceInputStream in project quick-media by liuyueyi.
the class PNGRed method parse_IEND_chunk.
private void parse_IEND_chunk(PNGChunk chunk) throws Exception {
// Store text strings
int textLen = textKeys.size();
String[] textArray = new String[2 * textLen];
for (int i = 0; i < textLen; i++) {
String key = (String) textKeys.get(i);
String val = (String) textStrings.get(i);
textArray[2 * i] = key;
textArray[2 * i + 1] = val;
if (emitProperties) {
String uniqueKey = "text_" + i + ':' + key;
properties.put(uniqueKey.toLowerCase(), val);
}
}
if (encodeParam != null) {
encodeParam.setText(textArray);
}
// Store compressed text strings
int ztextLen = ztextKeys.size();
String[] ztextArray = new String[2 * ztextLen];
for (int i = 0; i < ztextLen; i++) {
String key = (String) ztextKeys.get(i);
String val = (String) ztextStrings.get(i);
ztextArray[2 * i] = key;
ztextArray[2 * i + 1] = val;
if (emitProperties) {
String uniqueKey = "ztext_" + i + ':' + key;
properties.put(uniqueKey.toLowerCase(), val);
}
}
if (encodeParam != null) {
encodeParam.setCompressedText(ztextArray);
}
// Parse prior IDAT chunks
InputStream seqStream = new SequenceInputStream(Collections.enumeration(streamVec));
InputStream infStream = new InflaterInputStream(seqStream, new Inflater());
dataStream = new DataInputStream(infStream);
// Create an empty WritableRaster
int depth = bitDepth;
if ((colorType == PNG_COLOR_GRAY) && (bitDepth < 8) && output8BitGray) {
depth = 8;
}
if ((colorType == PNG_COLOR_PALETTE) && expandPalette) {
depth = 8;
}
int width = bounds.width;
int height = bounds.height;
int bytesPerRow = (outputBands * width * depth + 7) / 8;
int scanlineStride = (depth == 16) ? (bytesPerRow / 2) : bytesPerRow;
theTile = createRaster(width, height, outputBands, scanlineStride, depth);
if (performGammaCorrection && (gammaLut == null)) {
initGammaLut(bitDepth);
}
if ((postProcess == POST_GRAY_LUT) || (postProcess == POST_GRAY_LUT_ADD_TRANS) || (postProcess == POST_GRAY_LUT_ADD_TRANS_EXP)) {
initGrayLut(bitDepth);
}
decodeImage(interlaceMethod == 1);
// Free resources associated with compressed data.
dataStream.close();
infStream.close();
seqStream.close();
streamVec = null;
SampleModel sm = theTile.getSampleModel();
ColorModel cm;
if ((colorType == PNG_COLOR_PALETTE) && !expandPalette) {
if (outputHasAlphaPalette) {
cm = new IndexColorModel(bitDepth, paletteEntries, redPalette, greenPalette, bluePalette, alphaPalette);
} else {
cm = new IndexColorModel(bitDepth, paletteEntries, redPalette, greenPalette, bluePalette);
}
} else if ((colorType == PNG_COLOR_GRAY) && (bitDepth < 8) && !output8BitGray) {
byte[] palette = expandBits[bitDepth];
cm = new IndexColorModel(bitDepth, palette.length, palette, palette, palette);
} else {
cm = createComponentColorModel(sm);
}
init((CachableRed) null, bounds, cm, sm, 0, 0, properties);
}
Aggregations