gigaZhang / thumbnailator

Automatically exported from code.google.com/p/thumbnailator
Other
0 stars 0 forks source link

Exception on opening nested folder #63

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.The folder structure I've is something like J:\test\folder\...
2.I'm using the below code in a standalone java program: 

        File parentFile = new File("J:\\test);
        Thumbnails.of(parentFile.listFiles())
        .size(1024, 768)
        .outputFormat("jpg")
        .toFiles(Rename.PREFIX_DOT_THUMBNAIL);

3.Running it as administrator to make sure its not permission issue.

What is the expected output? What do you see instead?
The expected behavior is to produce the thumbnails of the files in nested 
folders, however I'm getting the IO exception, and the stack trace is as 
provided below :

java.io.IOException: Could not open file: J:\test\folder
    at net.coobird.thumbnailator.tasks.io.FileImageSource.read(Unknown Source)
    at net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask.read(Unknown Source)
    at net.coobird.thumbnailator.Thumbnailator.createThumbnail(Unknown Source)
    at net.coobird.thumbnailator.Thumbnails$Builder.asFiles(Unknown Source)
    at net.coobird.thumbnailator.Thumbnails$Builder.toFiles(Unknown Source)
    at CreateThumbnail.generateThumbnail(CreateThumbnail.java:28)
    at CreateThumbnail.main(CreateThumbnail.java:18) 

What version of the product are you using? On what operating system? Which
version of Java (Sun/Oracle? OpenJDK?) ?

Operating System : Windows 7
Java Version : Oracle JDK build 1.8.0
Product Version : Thumbnailator 0.4.6

Please provide any additional information below.
Its working as expected when I provide the path till first parent folder of 
image.

Original issue reported on code.google.com by dhawansh...@gmail.com on 21 Dec 2013 at 3:19

GoogleCodeExporter commented 9 years ago
Thank you for filing this issue and bringing it to my attention.
I appreciate all the details you've provided.

This is indeed a quite plausible scenario which can cause problems.
Although I have not tried to reproduce this issue, I can imagine that this 
problem will occur.

Therefore, at the very least, Thumbnailator should be changed to not die when 
it encounters a directory.

How to Handle Nested Folders
----------------------------
I'm leaning toward *not* performing a resize of the nested folders by default, 
with the reason being, how to handle the file names and folder structure of the 
thumbnails being output.

I can imaging the following scenario:

  root/
       image.jpg
       drawing.png
       folder/
              photo.jpg
              drawing.png

Now, the question will be how the thumbnails should be laid out.
A few options can be:

  1. Thumbnails of all files, including nested ones, will be placed in the same folder.
    => Problem being that `root/drawing.png` and `root/folder/drawing.png` will have a file name collision.
  2. Thumbnails of all files, including nested ones, will be placed in the original folder.
    => This may clash with Issue 51, as what should happen if a separate directory is set as the output directory?
       Also, should be nested directories be created in this case? Should be directory names be the same?

As handling nested directories can become very complex, I think it should be a 
completely separate issue from graceful handling of input directories which 
contains other directories.

Handling all scenarios can add complexity and lead to many edge cases (which 
can lead to many bugs), I'd rather try to keep things simple.

I'd be interested in how you think. :)

Thank you for bringing this issue to my attention!

Original comment by coobird...@gmail.com on 21 Dec 2013 at 10:58

GoogleCodeExporter commented 9 years ago
On second thought, I was getting this all wrong with the previous comment.

First, since the `Thumbnails.of` accepts a list of `File`s, if it is given a 
directory, its only choices will be:

  a. Reject the non-file input and stop, which is the current behavior, or
  b. Start processing nested directories recursively.

However, considering the Thumbnailator API dictates that it should get "image 
files"[1], handing it a directory is a not a valid use of the 
`Thumbnails.of(File...)` method -- a directory is not an image file.

Therefore, I'm not going to change this behavior, as it is by design.

That said, there probably are use cases for wanting to recursively process 
directories with images, I'm going to make a separate ticket as a Request for 
Enhancement.

Thank you for filing this issue, as it's indeed an issue that I can expect 
people to encounter through normal use of Thumbnailator.

[1]: 
http://thumbnailator.googlecode.com/hg/javadoc/net/coobird/thumbnailator/Thumbna
ils.html#of(java.io.File...)

Original comment by coobird...@gmail.com on 21 Dec 2013 at 3:33

GoogleCodeExporter commented 9 years ago
I've created Issue 64, which is a feature request for recursively processing 
nested directories.

Original comment by coobird...@gmail.com on 21 Dec 2013 at 3:37

GoogleCodeExporter commented 9 years ago
Thanks for responding promptly. Actually you're right that it isn't a bug, 
however a much needed enhancement for sure. I've the exact use case which is 
referred in your 1st comment. Since I only had the .jpg files in the 
directories, I was able to get through using Java 7 File tree walker api [1].

So, thanks for creating the ticket for enhancement and for providing the great 
library.

[1]:http://docs.oracle.com/javase/tutorial/essential/io/walk.html

Original comment by dhawansh...@gmail.com on 22 Dec 2013 at 10:44

GoogleCodeExporter commented 9 years ago
Thank you for the heads up on the file tree walking API of Java 7 -- I haven't 
been up-to-speed with the new features of Java 7, so I'll try to keep it in 
mind when I have a need for it!

I'm glad you found Thumbnailator useful :)

Original comment by coobird...@gmail.com on 24 Dec 2013 at 3:41