Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Unified Diff: client/tools/dartserver/java/com/google/appstack/tools/AwtThumbnailServlet.java

Issue 8341078: Archive dartserver code (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: client/tools/dartserver/java/com/google/appstack/tools/AwtThumbnailServlet.java
diff --git a/client/tools/dartserver/java/com/google/appstack/tools/AwtThumbnailServlet.java b/client/tools/dartserver/java/com/google/appstack/tools/AwtThumbnailServlet.java
deleted file mode 100644
index 7d9b63e8b9bad190603cdcf1b471aa4ec9e8a57e..0000000000000000000000000000000000000000
--- a/client/tools/dartserver/java/com/google/appstack/tools/AwtThumbnailServlet.java
+++ /dev/null
@@ -1,101 +0,0 @@
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package com.google.appstack.tools;
-
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.net.URL;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.imageio.IIOImage;
-import javax.imageio.ImageIO;
-import javax.imageio.ImageWriteParam;
-import javax.imageio.ImageWriter;
-import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
-import javax.imageio.stream.ImageOutputStream;
-
-/**
- * This servlet takes images URLs and replies with a resized thumbnail of the
- * image. Unlike the "real" thumbnail servlet, this one doesn't use any
- * AppEngine libs, so can be run locally on top of Jetty.
- */
-public class AwtThumbnailServlet extends ThumbnailServlet {
- private static Logger logger =
- Logger.getLogger(AwtThumbnailServlet.class.getName());
-
- @Override
- protected byte[] makeThumbnail(URL originalUrl, int width, int height) {
- // Read the original image.
- BufferedImage image;
- try {
- image = ImageIO.read(originalUrl);
-
- // Resize it.
- // TODO(rnystrom): This doesn't use the exact same cropping and resize
- // logic as the "real" AppEngine thumbnail server. Consider the GSE one a
- // cheap approximation.
- BufferedImage resized = new BufferedImage(width, height,
- BufferedImage.TYPE_INT_RGB);
-
- Graphics2D g = resized.createGraphics();
-
- g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
- RenderingHints.VALUE_INTERPOLATION_BILINEAR);
- g.setRenderingHint(RenderingHints.KEY_RENDERING,
- RenderingHints.VALUE_RENDER_QUALITY);
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
-
- g.drawImage(image, 0, 0, width, height, null);
- g.dispose();
-
- return makeJpeg(resized);
- } catch (IOException e) {
- // TODO(rnystrom): Handle error better.
- logger.log(Level.SEVERE, "Got error generating thumbnail.", e);
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Create a compressed JPEG from the given image and return its data.
- */
- private byte[] makeJpeg(BufferedImage image) {
- try {
- Iterator<ImageWriter> iterator = ImageIO.getImageWritersByFormatName("jpg");
- ImageWriter writer = iterator.next();
-
- ByteArrayOutputStream output = new ByteArrayOutputStream();
- ImageOutputStream imageOutput = ImageIO.createImageOutputStream(output);
- writer.setOutput(imageOutput);
-
- ImageWriteParam param = new JPEGImageWriteParam(Locale.getDefault());
-
- param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
- param.setCompressionQuality(0.75F);
-
- writer.write(null, new IIOImage(image, null, null), param);
-
- imageOutput.flush();
- writer.dispose();
- imageOutput.close();
-
- return output.toByteArray();
- } catch (IOException e) {
- // TODO(rnystrom): Handle error better.
- logger.log(Level.SEVERE, "Got error creating JPEG.", e);
- throw new RuntimeException(e);
- }
- }
-
-
-
-}

Powered by Google App Engine
This is Rietveld 408576698