本文整理汇总了Java中org.apache.sanselan.Sanselan.guessFormat方法的典型用法代码示例。如果您正苦于以下问题:Java Sanselan.guessFormat方法的具体用法?Java Sanselan.guessFormat怎么用?Java Sanselan.guessFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.sanselan.Sanselan
的用法示例。
在下文中一共展示了Sanselan.guessFormat方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: canDecodeInput
import org.apache.sanselan.Sanselan; //导入方法依赖的package包/类
public boolean canDecodeInput(Object input) throws IOException {
if (!(input instanceof ImageInputStream)) {
return false;
}
final ImageInputStream stream = (ImageInputStream)input;
try {
final ImageFormat imageFormat = Sanselan.guessFormat(new MyByteSource(stream));
if (myFormats.contains(imageFormat)) {
myFormat.set(imageFormat);
return true;
}
return false;
}
catch (ImageReadException e) {
throw new IOException(e);
}
}
示例2: readIconData
import org.apache.sanselan.Sanselan; //导入方法依赖的package包/类
private IconData readIconData(byte[] iconData, IconInfo fIconInfo)
throws ImageReadException, IOException
{
ImageFormat imageFormat = Sanselan.guessFormat(iconData);
if (imageFormat.equals(ImageFormat.IMAGE_FORMAT_PNG))
{
BufferedImage bufferedImage = Sanselan.getBufferedImage(iconData);
PNGIconData pngIconData = new PNGIconData(fIconInfo, bufferedImage);
return pngIconData;
}
else
{
try
{
return readBitmapIconData(iconData, fIconInfo);
}
catch (ImageWriteException imageWriteException)
{
IOException ioe = new IOException();
ioe.initCause(imageWriteException);
throw ioe;
}
}
}
示例3: canRead
import org.apache.sanselan.Sanselan; //导入方法依赖的package包/类
@Override
public boolean canRead(final InputStream stream, final String name) {
try {
final ByteSource src = new ByteSourceInputStream(stream, name);
return Sanselan.guessFormat(src) != ImageFormat.IMAGE_FORMAT_UNKNOWN;
} catch (final Exception e) {
return false;
}
}
示例4: rewriteProxiedImage
import org.apache.sanselan.Sanselan; //导入方法依赖的package包/类
/**
* We don't actually rewrite the image we just ensure that it is in fact a valid
* and known image type.
*/
private boolean rewriteProxiedImage(HttpRequest request, HttpResponse resp,
MutableContent content) {
boolean imageIsSafe = false;
try {
String contentType = resp.getHeader("Content-Type");
if (contentType == null || contentType.toLowerCase().startsWith("image/")) {
// Unspecified or unknown image mime type.
try {
ImageFormat imageFormat = Sanselan
.guessFormat(new ByteSourceInputStream(resp.getResponse(),
request.getUri().getPath()));
if (imageFormat == ImageFormat.IMAGE_FORMAT_UNKNOWN) {
logger.log(Level.INFO, "Unable to sanitize unknown image type "
+ request.getUri().toString());
return true;
}
imageIsSafe = true;
// Return false to indicate that no rewriting occurred
return false;
} catch (IOException ioe) {
throw new RuntimeException(ioe);
} catch (ImageReadException ire) {
// Unable to read the image so its not safe
logger.log(Level.INFO, "Unable to detect image type for " +request.getUri().toString() +
" for sanitized content", ire);
return true;
}
} else {
return true;
}
} finally {
if (!imageIsSafe) {
content.setContent("");
}
}
}