Java POI - can't access xls file on Win 2003 Server - java

i have a small app. it takes xls file and transforms it into xml. everything works fine on my two local machines win xp 32 (java 7) and win 7 64 (java 8) but when i started app on win 2003 server things went a bit strange.
on win server it gives me error:
org.apache.poi.EmptyFileException: The supplied file was empty (zero bytes long)
at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:218)
at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:168)
at Parser.xlsToXml(Parser.java:43)
at Parser.<init>(Parser.java:28)
as you can see i use java poi lib to parse xls.
this is part of code where error occures:
Biff8EncryptionKey.setCurrentUserPassword(params.get("pass"));
NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(params.get("xls_location")), true);//string 43!!!
before i try to access this xls file i'm successfully getting params for app to work from text file located in the same folder on server as xls file is with this code:
encoded = Files.readAllBytes(Paths.get(dir+fileName));
return new String(encoded,getFileCharset(dir+fileName));
so i mean that i have all rights for reading and writing in the directory.
i tried to google this but found nothing that could help. i'm really stuck here. folder on the server has same right as folders on my win xp and win 7 home computers. also i allways use the same xls file on all machines.
so what do i do wrong?..
any help appriciated!

Related

Corrupt extraction with ZipArchive in PHP

I have a PHP script that must unzip some uploads. The uploads are packed folders, basically zip files with a custom extension.
I am having problems with some zip files packed in one machine, but not with the same folder packed in another machine. In both cases, the compression is done with the same Java library.
This is the expected result, which then PHP further proceses:
This is the corrupted result, which makes PHP choke:
If I look at their permissions, this is what I see (01_Orig is okay, 02_Modif is corrupted):
If I look at the two packages with unzip -l (the first one is okay, the second one is corrupt):
And this is my PHP function (which is the same in both cases):
$uploads = "uploads_dir/";
$dir = new DirectoryIterator("uploads_dir/");
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot()) {
$filename = $fileinfo->getFilename();
$zip = new ZipArchive;
$res = $zip->open($uploads . $fileinfo);
if ($res === TRUE) {
$zip->extractTo($uploads . $filename . "_extracted");
$zip->close();
} else {
echo "Unable to unzip";
}
}
}
Both uploads look fine when I manually unzip or open them with 7zip in my Windows machine.
If I create two hex dumps of both zip files and compare them, this is what I get: https://gist.github.com/msoutopico/22a9ef647381c2e4d26313f135c526e2
Thanks a lot in advance for any tips.
UPDATE:
In case it's relevant, the zip files are created (saved) in a linux server, and both machines where this is done (the one that works, and the one that corrupt the package) run Windows 10.
Sorted. Version 2 of the plugin was tweaked to transform path separators from \ to / in filenames. Now, even though the version 3 of the plugin was installed in both machines, in the faulty machine there was also an older one (version 1, previous to that tweak), which is the one that was being used instead of version 3. Just removing the version 1 duplicate has fixed the problem. #pmqs was right. Thank you everyone for helping me quickly solve this!

Not able to move file in the linux OS using java files.move

I am trying to move files (in linux OS) by using java code this happen when trying to move single file. Issue which looks to me is i guess similar to
java.nio.Files.move() - DirectoryNotEmptyException on OS X
If so how can we handle it . Shall it be done on linux level or java.
Files.move(src, dst, new CopyOption[] { StandardCopyOption.REPLACE_EXISTING });
in this src folder is present in projs/dd/output/TAR
and dest folder is config_files/billing/xml/workArea
the error which comes is even though destination there is no file present nor folder in target:
WARNING: FAILED_TO$Failed to get MHS user handler
java.nio.file.DirectoryNotEmptyException:
config_files/billing/xml/workArea/GBF_2017030001_000007540_00001_0000000004
at sun.nio.fs.UnixCopyFile.move(UnixCopyFile.java:491)
at sun.nio.fs.UnixFileSystemProvider.move(UnixFileSystemProvider.java:262)
at java.nio.file.Files.move(Files.java:1347)
what i could see is both folders are on different FileSystem
by running stat -c "%d" "${Folder}" on linux OS.
is this cause of exception

Not able to download a large file in java ftp

I am working on a project in JavaFX. I need to download a file from the server for that I am using the ftp connection and downloading the file.
The size of the file is 560 MB, while downloading the file the code doesn't give any error but when I check the size of the file in the download location it is only 485 MB and I am not able to open it.
My code for downloading is:
OutputStream output = new FileOutputStream(toPath + "/" + dfile);
if(ftpClient.retrieveFile(dfile, output))
{
downloadButton.setDisable(true);
}
output.close();
Does java ftp have some download file size limit? How to resolve this problem? I have heard of chunking but don't know how to implement it in this case.
I downloaded the files in binary mode and it's working fine now.
ftpClient.setFileType(FTP.BINARY_FILE_TYPE)

com.sun.star.lang.IllegalArgumentException - Unsupported URL <file:///

Hi Stackoverflow community, i am having an issue about reading a file from my java webapp. I want to get a file from a directory in my webapp, then converting it to PDF. Everything works just fine in my developpement environement ( Windows) but when i am puting this on sever ( LINUX), when the server reach the code to read my doc file to convert it, java throw this exception :
com.sun.star.lang.IllegalArgumentException - Unsupported URL <file:///
Here is the code :
fileDocToConvert = new File(GET_REAL_PATH()+repo_Name+slash+fileName);
fileDocToConvert path become then : /usr/share/tomcat7/webapps/myapp/repo_name/exemple.doc
the exception fired up when i try to convert :
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
connection.connect();
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
//HERE...=> // converter.convert(docFile, pdfFile);
I am using :
jodConverter 2.2.1, openOffice 3, Java7, Tomcat 7
I start the openOffice service this way :
soffice --headless --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard
I can't get a way to follow to solve this issue.
Thank you in advance
I resolved the problem, by installing some missing components of OpenOffice ( Calc, Writer ). The problem was that OpenOffice can't understand the path of the file given to it.
Thank's for your help millimoose.
Have got java.lang.Exception: Unsupported URL <file:////... error message when started multiple libreoffice instances from different users and with conflicting same port setting.
The problem for me was that OpenOffice or another program that uses components of OpenOffice in it cannot understand the path of the file given to it as a place to save the file. Save the file that you are trying to save somewhere else on your computer and see if that works.

java.io.IOException: Permission denied on network folder

i'm having the the post's title error when trying to write a file on a window folder , mounted on unix system. I've developed a web service which runs inside a Tomcat 6 on a linux os and need to write on a windows network folder. System administrators have mounted it on the Linux sever and have no problem to create and modify a file on it.
When i try to execute the posted code i get the following exception :
Permission denied
java.io.IOException: Permission denied
at java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:850)
The weird thing is that it seems to be related to the File.createNewFile method on a network folder , in fact the service can write on local file system without problems, both on debug (the pc i use to develop the service) and a tomcat folder system administrators have provided me on the linux server. The file gets created but is empty and the log entry following the create method doesn't get printed. Moreover if i use a plain outputstream to create and write the file i've no problems.
I cannot find any explanation about the exception on the web. Since i'm not very experienced with java , i'd like to understand why i'm getting this error. Am i using it in the wrong way ? Is it a bug of the library ? Do i miss to pass some parameter ?
As stated , i've solved the problem using a plain outputstream, this is a question to improve my understanding of java.
FileOutputStream fos = null;
try{
log.info(String.format("file length: %s",streamAttach.length));
log.info(String.format("check File : %s",filename));
File f = new File(filename);
if(f.exists())
...
boolean done= f.createNewFile();//here comes the exception
//nothing of the following happens
if(!done)
throw new NWSException("error creating file");
log.info(String.format("file %s creato", nomeFile));
thank you in advance for any answer
I ran into this problem recently and found that java.io.File.createNewFile() actually requires the "Change Permissions" permission (you can find this entry under Security->Advanced when checking folder permissions). Without this it will create the file and then subsequently throw an IOException.
It's deceptive because you will still be able to create files on the folder when manually testing, however createNewFile() will still fail if it doesn't have this particular permission (presumably such that it can change the permissions on the file its creating).
If you are using Netapp that shares an NTFS (CIFS) style filesystem to Unix you could be experience "NFS is not allowed to change permissions on a file in an NTFS-style security volume." (TR-3490 page 16)
Options here are to change to a unix filesystem or set the cifs.ntfs_ignore_unix_security_ops flag to on for the file system which quiches the NFS permission error.
java.io.UnixFileSystem.createFileExclusively(Native Method) opens the file with the O_EXCL and 0666 umask so I would get a EACCES, which really was a NFS3RR_ACCES
open("/net/storage01-a/filer/myfile", O_RDWR|O_CREAT|O_EXCL, 0666) Err#13 EACCES
Also you can use OutputStream to create the file, that does not use O_EXCL it seemes
It definitely not Java specific problem. If this Unix folder is mapped to your windows try to open file explorer and create file in this directory. I believe that you will get permission denied too. In this case fix this problem or ask your system administrator to help you.
Good luck!

Categories

Resources