Skip to content
Advertisement

java.io.IOException: File Size Incorrect (only get error on linux (CentOS 6))

I’m trying to rebuild an old java wrapper script for a game, but i don’t know why i get an error when i run it in in my VPS (CentOS 6), i only get the error when i’m running it in there, in my mac or pc with windows 10 it doesn’t happen…

Already took a look here on stackoverflow and i saw a common similar error and that is because the size becomes -1 but i guess that is not the case here:

INFO: Downloading the latest version of StarMade (length: 179840020 bytes, URL: http://files.star-made.org/build/starmade-build_20160413_201539.zip)...

“ls -lha:”

-rw-r--r-- 1 root root 172M Apr 18 11:05 StarMade-latest.zip

and as 179840020 bytes ~= 171,5 megabytes

Here is the error:

java.io.IOException: File downloaded is the incorrect size!
    at com.diogosaraiva.starmade.wrapper.VersionManager.downloadUpdate(VersionManager.java:127)
    at com.diogosaraiva.starmade.wrapper.server.Server.<init>(Server.java:90)
    at com.diogosaraiva.starmade.wrapper.ServerWrapper.main(ServerWrapper.java:24)

here’s some of VersionManager.java

final URL url = new URL(remotePath);
        final URLConnection connection = url.openConnection();
        final int size = connection.getContentLength();

        if (size < 0) {
            ServerWrapper.getLogger().info("Unable to get the latest version of StarMade!");
        } else {
            ServerWrapper.getLogger().info("Downloading the latest version of StarMade (length: " + size + " bytes, URL: " + remotePath + ")...");
        }

        inputStream = new BufferedInputStream(url.openStream());
        outputStream = new FileOutputStream("StarMade-latest.zip");

        final byte data[] = new byte[1024];
        int count;
        double sumCount = 0.0;
        int percentage;
        int lastPercentage = 0;

        while ((count = inputStream.read(data, 0, 1024)) != -1) {
            outputStream.write(data, 0, count);

            sumCount += count;

            percentage = (int) Math.ceil(sumCount / size * 100);

            if (percentage != lastPercentage) {
                ServerWrapper.getLogger().info(percentage + "%");
            }

            lastPercentage = percentage;
        }

        if (inputStream != null) {
            inputStream.close();
        }
        if (outputStream != null) {
            outputStream.close();
        }

        ServerWrapper.getLogger().info("Download finished. ");

        if (isInstalled() && backup) {
            ServerWrapper.getLogger().info("Backing up server.");
            final File f = new File(new SimpleDateFormat("'backup-'MM-dd hh-mm-ss-SS'.zip'").format(new Date()));
            if (!f.exists()) {
                f.createNewFile();
            }
            ZipUtils.zipDirectory(starmadeDirectory, f);
        }

        if (!starmadeDirectory.exists()) {
            starmadeDirectory.mkdirs();
        }
        ServerWrapper.getLogger().info("Installing update.");

        final File starmadeUpdate = new File("starmade-latest.zip");

        if (starmadeUpdate.length() != size) {
            throw new IOException("File downloaded is the incorrect size!");
        }

So, why am I getting that error?

EDIT: I’m running as root and the CentOS i’m running with is without Desktop Enviroment. I already tried with openjdk and oracle jdk

Advertisement

Answer

The issue is that file names are case sensitive on Linux.

outputStream = new FileOutputStream("StarMade-latest.zip");
...
final File starmadeUpdate = new File("starmade-latest.zip");

The file starmade-latest.zip does probably not even exist in that directory. So your if (starmadeUpdate.length() != size) will compare zero with the lenght of the downloaded file.

Check the file names and the issue should disappear.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement