本文整理汇总了Java中org.apache.sanselan.ImageFormat.IMAGE_FORMAT_UNKNOWN属性的典型用法代码示例。如果您正苦于以下问题:Java ImageFormat.IMAGE_FORMAT_UNKNOWN属性的具体用法?Java ImageFormat.IMAGE_FORMAT_UNKNOWN怎么用?Java ImageFormat.IMAGE_FORMAT_UNKNOWN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.sanselan.ImageFormat
的用法示例。
在下文中一共展示了ImageFormat.IMAGE_FORMAT_UNKNOWN属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: canRead
@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;
}
}
示例2: rewriteProxiedImage
/**
* 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("");
}
}
}
示例3: MyImageReader
private MyImageReader(final SanselanImageReaderSpi provider, final ImageFormat imageFormat) {
super(provider);
myDefaultFormat = imageFormat == null? ImageFormat.IMAGE_FORMAT_UNKNOWN : imageFormat;
}