本文整理汇总了Java中org.apache.commons.imaging.util.IoUtils类的典型用法代码示例。如果您正苦于以下问题:Java IoUtils类的具体用法?Java IoUtils怎么用?Java IoUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IoUtils类属于org.apache.commons.imaging.util包,在下文中一共展示了IoUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setData
import org.apache.commons.imaging.util.IoUtils; //导入依赖的package包/类
public void setData(final byte[] bytes) throws IOException {
data = bytes;
InputStream bis = null;
boolean canThrow = false;
try {
bis = new ByteArrayInputStream(bytes);
dataTypeSignature = BinaryFunctions.read4Bytes("data type signature", bis,
"ICC: corrupt tag data", ByteOrder.BIG_ENDIAN);
itdt = getIccTagDataType(dataTypeSignature);
// if (itdt != null)
// {
// System.out.println("\t\t\t" + "itdt: " + itdt.name);
// }
canThrow = true;
} finally {
IoUtils.closeQuietly(canThrow, bis);
}
}
示例2: getAllBufferedImages
import org.apache.commons.imaging.util.IoUtils; //导入依赖的package包/类
@Override
public List<BufferedImage> getAllBufferedImages(final ByteSource byteSource)
throws ImageReadException, IOException {
final DcxHeader dcxHeader = readDcxHeader(byteSource);
final List<BufferedImage> images = new ArrayList<BufferedImage>();
final PcxImageParser pcxImageParser = new PcxImageParser();
for (final long element : dcxHeader.pageTable) {
InputStream stream = null;
boolean canThrow = false;
try {
stream = byteSource.getInputStream(element);
final ByteSourceInputStream pcxSource = new ByteSourceInputStream(
stream, null);
final BufferedImage image = pcxImageParser.getBufferedImage(
pcxSource, new HashMap<String, Object>());
images.add(image);
canThrow = true;
} finally {
IoUtils.closeQuietly(canThrow, stream);
}
}
return images;
}
示例3: readBmpHeaderInfo
import org.apache.commons.imaging.util.IoUtils; //导入依赖的package包/类
private BmpHeaderInfo readBmpHeaderInfo(final ByteSource byteSource,
final boolean verbose) throws ImageReadException, IOException {
InputStream is = null;
boolean canThrow = false;
try {
is = byteSource.getInputStream();
// readSignature(is);
final BmpHeaderInfo ret = readBmpHeaderInfo(is, null, verbose);
canThrow = true;
return ret;
} finally {
IoUtils.closeQuietly(canThrow, is);
}
}
示例4: getFormatCompliance
import org.apache.commons.imaging.util.IoUtils; //导入依赖的package包/类
@Override
public FormatCompliance getFormatCompliance(final ByteSource byteSource)
throws ImageReadException, IOException {
final boolean verbose = false;
final FormatCompliance result = new FormatCompliance(
byteSource.getDescription());
InputStream is = null;
boolean canThrow = false;
try {
is = byteSource.getInputStream();
readImageContents(is, result, verbose);
canThrow = true;
} finally {
IoUtils.closeQuietly(canThrow, is);
}
return result;
}
示例5: getBufferedImage
import org.apache.commons.imaging.util.IoUtils; //导入依赖的package包/类
@Override
public BufferedImage getBufferedImage(final ByteSource byteSource, final Map<String, Object> params)
throws ImageReadException, IOException {
InputStream is = null;
boolean canThrow = false;
try {
is = byteSource.getInputStream();
final FileInfo info = readHeader(is);
final int width = info.width;
final int height = info.height;
final boolean hasAlpha = info.hasAlpha();
final ImageBuilder imageBuilder = new ImageBuilder(width, height,
hasAlpha);
info.readImage(imageBuilder, is);
final BufferedImage ret = imageBuilder.getBufferedImage();
canThrow = true;
return ret;
} finally {
IoUtils.closeQuietly(canThrow, is);
}
}
示例6: readImageResourceBlocks
import org.apache.commons.imaging.util.IoUtils; //导入依赖的package包/类
private List<ImageResourceBlock> readImageResourceBlocks(
final ByteSource byteSource, final int[] imageResourceIDs, final int maxBlocksToRead)
throws ImageReadException, IOException {
InputStream imageStream = null;
InputStream resourceStream = null;
boolean canThrow = false;
try {
imageStream = byteSource.getInputStream();
final ImageContents imageContents = readImageContents(imageStream);
resourceStream = this.getInputStream(byteSource, PSD_SECTION_IMAGE_RESOURCES);
final byte[] ImageResources = readBytes("ImageResources",
resourceStream, imageContents.ImageResourcesLength,
"Not a Valid PSD File");
final List<ImageResourceBlock> ret = readImageResourceBlocks(ImageResources, imageResourceIDs,
maxBlocksToRead);
canThrow = true;
return ret;
} finally {
IoUtils.closeQuietly(canThrow, imageStream, resourceStream);
}
}
示例7: getImageInfo
import org.apache.commons.imaging.util.IoUtils; //导入依赖的package包/类
@Override
public ImageInfo getImageInfo(final ByteSource byteSource, final Map<String, Object> params)
throws ImageReadException, IOException {
final RgbeInfo info = new RgbeInfo(byteSource);
boolean canThrow = false;
try {
final ImageInfo ret = new ImageInfo(
getName(),
32, // todo may be 64 if double?
new ArrayList<String>(), ImageFormats.RGBE, getName(),
info.getHeight(), "image/vnd.radiance", 1, -1, -1, -1, -1,
info.getWidth(), false, false, false,
ImageInfo.COLOR_TYPE_RGB, "Adaptive RLE");
canThrow = true;
return ret;
} finally {
IoUtils.closeQuietly(canThrow, info);
}
}
示例8: getBufferedImage
import org.apache.commons.imaging.util.IoUtils; //导入依赖的package包/类
@Override
public BufferedImage getBufferedImage(final ByteSource byteSource, final Map<String, Object> params)
throws ImageReadException, IOException {
final RgbeInfo info = new RgbeInfo(byteSource);
boolean canThrow = false;
try {
// It is necessary to create our own BufferedImage here as the
// org.apache.commons.imaging.common.IBufferedImageFactory interface does
// not expose this complexity
final DataBuffer buffer = new DataBufferFloat(info.getPixelData(),
info.getWidth() * info.getHeight());
final BufferedImage ret = new BufferedImage(new ComponentColorModel(
ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false,
Transparency.OPAQUE, buffer.getDataType()),
Raster.createWritableRaster(
new BandedSampleModel(buffer.getDataType(), info
.getWidth(), info.getHeight(), 3), buffer,
new Point()), false, null);
canThrow = true;
return ret;
} finally {
IoUtils.closeQuietly(canThrow, info);
}
}
示例9: getBufferedImage
import org.apache.commons.imaging.util.IoUtils; //导入依赖的package包/类
@Override
public final BufferedImage getBufferedImage(final ByteSource byteSource,
Map<String, Object> params) throws ImageReadException, IOException {
params = (params == null) ? new HashMap<String, Object>() : new HashMap<String, Object>(params);
boolean isStrict = false;
final Object strictness = params.get(PARAM_KEY_STRICT);
if (strictness != null) {
isStrict = ((Boolean) strictness).booleanValue();
}
InputStream is = null;
boolean canThrow = false;
try {
is = byteSource.getInputStream();
final PcxHeader pcxHeader = readPcxHeader(is, isStrict);
final BufferedImage ret = readImage(pcxHeader, is, byteSource);
canThrow = true;
return ret;
} finally {
IoUtils.closeQuietly(canThrow, is);
}
}
示例10: readChunks
import org.apache.commons.imaging.util.IoUtils; //导入依赖的package包/类
private List<PngChunk> readChunks(final ByteSource byteSource, final ChunkType[] chunkTypes,
final boolean returnAfterFirst) throws ImageReadException, IOException {
InputStream is = null;
boolean canThrow = false;
try {
is = byteSource.getInputStream();
readSignature(is);
final List<PngChunk> ret = readChunks(is, chunkTypes, returnAfterFirst);
canThrow = true;
return ret;
} finally {
IoUtils.closeQuietly(canThrow, is);
}
}
示例11: parseXpmHeader
import org.apache.commons.imaging.util.IoUtils; //导入依赖的package包/类
private XpmParseResult parseXpmHeader(final ByteSource byteSource)
throws ImageReadException, IOException {
InputStream is = null;
boolean canThrow = false;
try {
is = byteSource.getInputStream();
final StringBuilder firstComment = new StringBuilder();
final ByteArrayOutputStream preprocessedFile = BasicCParser.preprocess(
is, firstComment, null);
if (!"XPM".equals(firstComment.toString().trim())) {
throw new ImageReadException("Parsing XPM file failed, "
+ "signature isn't '/* XPM */'");
}
final XpmParseResult xpmParseResult = new XpmParseResult();
xpmParseResult.cParser = new BasicCParser(new ByteArrayInputStream(
preprocessedFile.toByteArray()));
xpmParseResult.xpmHeader = parseXpmHeader(xpmParseResult.cParser);
canThrow = true;
return xpmParseResult;
} finally {
IoUtils.closeQuietly(canThrow, is);
}
}
示例12: getBlock
import org.apache.commons.imaging.util.IoUtils; //导入依赖的package包/类
@Override
public byte[] getBlock(final long start, final int length) throws IOException {
RandomAccessFile raf = null;
boolean canThrow = false;
try {
raf = new RandomAccessFile(file, "r");
// We include a separate check for int overflow.
if ((start < 0) || (length < 0) || (start + length < 0)
|| (start + length > raf.length())) {
throw new IOException("Could not read block (block start: "
+ start + ", block length: " + length
+ ", data length: " + raf.length() + ").");
}
final byte[] ret = BinaryFunctions.getRAFBytes(raf, start, length,
"Could not read value from file");
canThrow = true;
return ret;
} finally {
IoUtils.closeQuietly(canThrow, raf);
}
}
示例13: getAll
import org.apache.commons.imaging.util.IoUtils; //导入依赖的package包/类
@Override
public byte[] getAll() throws IOException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream is = null;
boolean canThrow = false;
try {
is = new FileInputStream(file);
is = new BufferedInputStream(is);
final byte[] buffer = new byte[1024];
int read;
while ((read = is.read(buffer)) > 0) {
baos.write(buffer, 0, read);
}
final byte[] ret = baos.toByteArray();
canThrow = true;
return ret;
} finally {
IoUtils.closeQuietly(canThrow, is);
}
}
示例14: setExifGPSTag
import org.apache.commons.imaging.util.IoUtils; //导入依赖的package包/类
/**
* This method sets the EXIF the of the JPEG file and outputs it to given directory.
* @param jpegImageFile
* Input jpeg file.
* @param dst
* output jpeg file.
* @param longitude
* Longitude to be tagged.
* @param latitude
* Latitude to be tagged.
* @throws IOException
* @throws ImageReadException
* @throws ImageWriteException
*/
public static void setExifGPSTag(final File jpegImageFile, final File dst, final double longitude, final double latitude) throws IOException,
ImageReadException, ImageWriteException {
OutputStream os = null;
boolean canThrow = false;
try {
final IImageMetadata metadata = Imaging.getMetadata(jpegImageFile);
final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
TiffOutputSet outputSet = setTiffOutputSet(jpegMetadata, longitude, latitude);
os = new FileOutputStream(dst);
os = new BufferedOutputStream(os);
new ExifRewriter().updateExifMetadataLossless(jpegImageFile, os, outputSet);
canThrow = true;
} finally {
IoUtils.closeQuietly(canThrow, os);
}
}
示例15: readDcxHeader
import org.apache.commons.imaging.util.IoUtils; //导入依赖的package包/类
private DcxHeader readDcxHeader(final ByteSource byteSource)
throws ImageReadException, IOException {
InputStream is = null;
boolean canThrow = false;
try {
is = byteSource.getInputStream();
final int id = read4Bytes("Id", is, "Not a Valid DCX File", getByteOrder());
final List<Long> pageTable = new ArrayList<Long>(1024);
for (int i = 0; i < 1024; i++) {
final long pageOffset = 0xFFFFffffL & read4Bytes("PageTable", is,
"Not a Valid DCX File", getByteOrder());
if (pageOffset == 0) {
break;
}
pageTable.add(pageOffset);
}
if (id != DcxHeader.DCX_ID) {
throw new ImageReadException(
"Not a Valid DCX File: file id incorrect");
}
if (pageTable.size() == 1024) {
throw new ImageReadException(
"DCX page table not terminated by zero entry");
}
final Object[] objects = pageTable.toArray();
final long[] pages = new long[objects.length];
for (int i = 0; i < objects.length; i++) {
pages[i] = ((Long) objects[i]);
}
final DcxHeader ret = new DcxHeader(id, pages);
canThrow = true;
return ret;
} finally {
IoUtils.closeQuietly(canThrow, is);
}
}