コード例 #1
0
 /** it's called in cycle and when base image 0 doesn't exists than there is forewer loop. */
 private FileResponse getNoImageStream(ResizeRequest request) throws IOException {
   String extension = noImage.getExtension();
   if (extension == null) {
     extension = getFileExtension(noImage.getIdFile());
     if (extension == null) {
       throw new IOException("NoImage is not defined");
     }
   }
   FileDescriptor descriptor =
       new FileDescriptor(noImage.getIdFile(), request.getCode(), extension);
   if (isExists(descriptor)) {
     File file = getFileForDescription(descriptor);
     return new FileResponse(noImage.getIdFile(), file, extension, getContentType(extension));
   } else {
     FileDescriptor mainFile = new FileDescriptor(noImage.getIdFile(), null, extension);
     if (isExists(mainFile)) {
       // try to resize original image
       OutputStream os = getFileWithSameExtensionAsMain(noImage.getIdFile(), request.getCode());
       getImageResizer().resize(getFileForId(noImage.getIdFile(), ""), os, request);
       os.close();
       if (!isExists(descriptor)) {
         // load default image
         logger.debug("file " + descriptor + " wasn't found, default will be loaded");
         throw new IOException("NoImage is not defined");
       }
       File file = getFileForDescription(descriptor);
       return new FileResponse(noImage.getIdFile(), file, extension, getContentType(extension));
     } else {
       // load default image
       logger.debug("file " + descriptor + " wasn't found, default will be loaded");
       throw new IOException("NoImage is not defined");
     }
   }
 }