Jinx
Jinx

Reputation: 73

File.length() different than windows, file contents still equal?

Read the update at the bottom

I've been scratching my head over this for a few hours and cannot seem to figure this out.

For a unit test, we copy a file to a temporary location and run soms scenario's on it. This file copy does VERY weird things. This only happens with PDF files, images were not affected. I've tried a few different ways of copying/gathering file sizes and all do the same thing.

the original:

xÚ¥‘=OÃ@†÷ü

the new file:

xڥ�=O�@���

This leads me to suspect an encoding issue or something alike...

But...

Has anyone come across something like this or knows in which direction i should search?

Upon request: This is the code used to copy the files:

assetFile = TempFileUtil.createTempFile(transformationId + "_" + inputFile.getName()); FileUtils.copyFile(inputFile, assetFile);

and the createTempFile method is:

public static File createTempFile(final String filename) { return new File(baseOutputPath, filename); }

update

I've discoverd that the fault was not with the copying but with the way resources are handled in unit tests. The /src/resources/ folder contents are moved/linked/copied to targer/test-classes/ folder so it is accessible in unit tests etc... and that is where is goes wrong... I'm still trying to find out why this is failing.

Upvotes: 1

Views: 962

Answers (2)

Jinx
Jinx

Reputation: 73

It turns out the maven resources plugin was badly configured. By default only a few basic image types are configured as "do not filter these" when filtering is set to true. adding PDF to this list solved the problem.

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <configuration> <nonFilteredFileExtensions> <nonFilteredFileExtension>pdf</nonFilteredFileExtension> <nonFilteredFileExtension>jpg</nonFilteredFileExtension> <nonFilteredFileExtension>jpeg</nonFilteredFileExtension> <nonFilteredFileExtension>gif</nonFilteredFileExtension> <nonFilteredFileExtension>png</nonFilteredFileExtension> <nonFilteredFileExtension>tif</nonFilteredFileExtension> <nonFilteredFileExtension>tiff</nonFilteredFileExtension> <nonFilteredFileExtension>bmp</nonFilteredFileExtension> </nonFilteredFileExtensions> </configuration> </plugin>

Upvotes: 0

user207421
user207421

Reputation: 310956

You're almost certainly not copying it correctly: for example, you're using Readers and Writers where you should be using input and output streams.

Upvotes: 1

Related Questions