Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. if ( Pattern.matches("png|jpg|jpeg", extension ) ) {
  2.  
  3.  
  4.                     String location =  requestURL;
  5.  
  6.                     //Open the stream from the location
  7.                     InputStream stream = new URL(location).openStream();
  8.  
  9.                     //Create image stream
  10.                     Object obj = ImageIO.createImageInputStream(stream);
  11.  
  12.                     //Setup the image reader
  13.                     ImageReader reader = ImageIO.getImageReaders(obj).next();
  14.  
  15.                     //reader.setInput(obj, false);
  16.                     reader.setInput(obj);
  17.  
  18.                     int w = reader.getWidth(0);
  19.  
  20.                 stream.close();
  21.  
  22.                  if( w > 480 ){
  23.  
  24.                     String toReplace = requestURI.substring( requestURI.lastIndexOf("."), requestURI.length() );
  25.  
  26.                     String newURI = requestURI.replace(toReplace, "");
  27.  
  28.                       if( newURI.contains("/dotAsset/") ){
  29.  
  30.                         newURI = newURI.replace("/dotAsset/", "");
  31.  
  32.                         doLog("Replacing Image : ");
  33.                         doLog( "/contentAsset/image/" + newURI + "/fileAsset/filter/Resize/resize_w/480" );
  34.  
  35.                         req.getRequestDispatcher( "/contentAsset/image/" + newURI + "/fileAsset/filter/Resize/resize_w/480" ).forward(req, res);
  36.  
  37.                    
  38.  
  39.                       }
  40.                       else{
  41.                           chain.doFilter(req, res);
  42.                       }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement