use of javax.imageio.stream.MemoryCacheImageInputStream in project openj9 by eclipse.
the class J9DDRStructureStore method get.
/**
* @param key
* @return An InputStream open and positioned at the start of the J9DDR structure the blob associated with key. null if key is not contained in the database
* @throws IOException - if there is a problem retrieving the blob
*/
public ImageInputStream get(StructureKey key) throws IOException {
String digest = keyMap.get(key);
if (digest == null) {
return null;
}
ZipFile zipFile = new ZipFile(getZipFile(key, digest));
ZipEntry entry = zipFile.getEntry(getZipEntry(key, digest).getName());
InputStream entryStream = zipFile.getInputStream(entry);
byte[] buffer = new byte[1024];
ByteArrayOutputStream output = new ByteArrayOutputStream((int) entry.getSize());
while (true) {
int bytesRead = entryStream.read(buffer);
if (bytesRead == -1) {
break;
}
output.write(buffer, 0, bytesRead);
}
zipFile.close();
return new MemoryCacheImageInputStream(new ByteArrayInputStream(output.toByteArray()));
}
use of javax.imageio.stream.MemoryCacheImageInputStream in project spring-security-oauth by spring-projects.
the class SparklrController method photo.
@RequestMapping("/sparklr/photos/{id}")
public ResponseEntity<BufferedImage> photo(@PathVariable String id, HttpServletRequest request) throws Exception {
InputStream photo = sparklrService.loadSparklrPhoto(id);
if (photo == null) {
throw new UnavailableException("The requested photo does not exist");
}
BufferedImage body;
MediaType contentType = MediaType.IMAGE_JPEG;
Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(contentType.toString());
if (imageReaders.hasNext()) {
ImageReader imageReader = imageReaders.next();
ImageReadParam irp = imageReader.getDefaultReadParam();
imageReader.setInput(new MemoryCacheImageInputStream(photo), true);
body = imageReader.read(0, irp);
} else {
throw new HttpMessageNotReadableException("Could not find javax.imageio.ImageReader for Content-Type [" + contentType + "]");
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.IMAGE_JPEG);
request.setAttribute(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(MediaType.IMAGE_JPEG));
return new ResponseEntity<BufferedImage>(body, headers, HttpStatus.OK);
}
use of javax.imageio.stream.MemoryCacheImageInputStream in project spring-security-oauth by spring-projects.
the class SparklrRedirectController method photo.
@RequestMapping("/sparklr/redirect/{id}")
public ResponseEntity<BufferedImage> photo(@PathVariable String id) throws Exception {
InputStream photo = sparklrService.loadSparklrPhoto(id);
if (photo == null) {
throw new UnavailableException("The requested photo does not exist");
}
BufferedImage body;
MediaType contentType = MediaType.IMAGE_JPEG;
Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(contentType.toString());
if (imageReaders.hasNext()) {
ImageReader imageReader = imageReaders.next();
ImageReadParam irp = imageReader.getDefaultReadParam();
imageReader.setInput(new MemoryCacheImageInputStream(photo), true);
body = imageReader.read(0, irp);
} else {
throw new HttpMessageNotReadableException("Could not find javax.imageio.ImageReader for Content-Type [" + contentType + "]");
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.IMAGE_JPEG);
return new ResponseEntity<BufferedImage>(body, headers, HttpStatus.OK);
}
use of javax.imageio.stream.MemoryCacheImageInputStream in project spring-security-oauth by spring-projects.
the class SparklrController method photo.
@RequestMapping("/sparklr/photos/{id}")
public ResponseEntity<BufferedImage> photo(@PathVariable String id) throws Exception {
InputStream photo = sparklrService.loadSparklrPhoto(id);
if (photo == null) {
throw new UnavailableException("The requested photo does not exist");
}
BufferedImage body;
MediaType contentType = MediaType.IMAGE_JPEG;
Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(contentType.toString());
if (imageReaders.hasNext()) {
ImageReader imageReader = imageReaders.next();
ImageReadParam irp = imageReader.getDefaultReadParam();
imageReader.setInput(new MemoryCacheImageInputStream(photo), true);
body = imageReader.read(0, irp);
} else {
throw new HttpMessageNotReadableException("Could not find javax.imageio.ImageReader for Content-Type [" + contentType + "]");
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.IMAGE_JPEG);
return new ResponseEntity<BufferedImage>(body, headers, HttpStatus.OK);
}
use of javax.imageio.stream.MemoryCacheImageInputStream in project pdfbox by apache.
the class LZWFilter method doLZWDecode.
private void doLZWDecode(InputStream encoded, OutputStream decoded, int earlyChange) throws IOException {
List<byte[]> codeTable = new ArrayList<>();
int chunk = 9;
final MemoryCacheImageInputStream in = new MemoryCacheImageInputStream(encoded);
long nextCommand;
long prevCommand = -1;
try {
while ((nextCommand = in.readBits(chunk)) != EOD) {
if (nextCommand == CLEAR_TABLE) {
chunk = 9;
codeTable = createCodeTable();
prevCommand = -1;
} else {
if (nextCommand < codeTable.size()) {
byte[] data = codeTable.get((int) nextCommand);
byte firstByte = data[0];
decoded.write(data);
if (prevCommand != -1) {
checkIndexBounds(codeTable, prevCommand, in);
data = codeTable.get((int) prevCommand);
byte[] newData = Arrays.copyOf(data, data.length + 1);
newData[data.length] = firstByte;
codeTable.add(newData);
}
} else {
checkIndexBounds(codeTable, prevCommand, in);
byte[] data = codeTable.get((int) prevCommand);
byte[] newData = Arrays.copyOf(data, data.length + 1);
newData[data.length] = data[0];
decoded.write(newData);
codeTable.add(newData);
}
chunk = calculateChunk(codeTable.size(), earlyChange);
prevCommand = nextCommand;
}
}
} catch (EOFException ex) {
LOG.warn("Premature EOF in LZW stream, EOD code missing", ex);
}
decoded.flush();
}
Aggregations