Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9227791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:09:59+00:00 2026-06-18T05:09:59+00:00

I am currently using TrueZip to add a file to a Zip file that

  • 0

I am currently using TrueZip to add a file to a Zip file that was uploaded to a server via MultiPartFile.

The Problem
Upon appending a file the zip becomes invalid. It can no longer be opened as a zip file.

The Code
Let’s start with the relevant code in my upload controller (file is the MultiPartFile):

    // Get the file
    File dest = null;
    TFile zip = null;
    try {
        // Obtain the file locally, zip, and delete the old
        dest = new File(request.getRealPath("") + "/datasource/uploads/" + fixedFileName);
        file.transferTo(dest);

        // Validate
        zip = new TFile(dest);
        resp = mls.validateMapLayer(zip);
        // Now perform the upload and delete the temp file
        FoundryUserDetails userDetails = (FoundryUserDetails) SecurityContextHolder.getContext().getAuthentication()
                .getPrincipal();
        UserIdentity ui = userDetails.getUserIdentity();

        MapLayer newLayer = new MapLayer();

                    // generate the prj
        mls.generateProjection(resp, dest.getAbsolutePath(), projection);

The method “generateProjection” is where the file is added:

public void generateProjection(UploadMapResponse resp, String fLoc, FoundryCRS proj) throws NoSuchAuthorityCodeException,
        FactoryException, IOException {
    TFile projFile = new TFile(fLoc, resp.getLayerName() + ".prj");
    CoordinateReferenceSystem crs = CRS.decode(proj.getEpsg());
    String wkt = crs.toWKT();
    TConfig config = TConfig.push();
    try {
        config.setOutputPreferences(config.getOutputPreferences().set(FsOutputOption.GROW));
        TFileOutputStream writer = new TFileOutputStream(projFile);
        try {
            writer.write(wkt.getBytes());
        } finally {
            writer.close();
        }
    } finally {
        config.close();
    }
}

In order to test if this worked at all I tried it in a simple main:

public static void main(String[] args) {
    File f = new File("C:/Data/SierritaDec2011TopoContours.zip");
    TFile tf = new TFile(f);
    tf.listFiles();

    TFile proj = new TFile(f, "test.prj");
    TConfig config = TConfig.push();
    try {
        config.setOutputPreferences(config.getOutputPreferences().set(FsOutputOption.GROW));
        TFileOutputStream writer = null;
        try {
            writer = new TFileOutputStream(proj);
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        }

        try {
            writer.write("Hello Zip world".getBytes());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            try {
                writer.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    } finally {
        // Pop the current configuration off the inheritable thread local
        // stack.
        config.close();
    }
}

Which, of course, works just fine.

The Question

Does anyone have insight into why, in a web server with a MultiPartFile copied to a local file, the TFileOutputStream fails to write properly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:10:01+00:00Added an answer on June 18, 2026 at 5:10 am

    In a long running server app, you may need to add a call to TVFS.sync() or TVFS.umount() in order to sync or umount archive files. In the case of ZIP files, this will trigger to write the Central Directory at the end of the ZIP file, which is required to form a valid ZIP file.

    Please check the Javadoc to decide which call is the best for your use case: http://truezip.java.net/apidocs/de/schlichtherle/truezip/file/TVFS.html

    Also, please note that calling TFVS.sync() or TVFS.umount() after each append operation will result in a growing Central Directory to be written each time, which results in huge overhead. So it’s worth to consider when exactly you need to do this. Generally speaking this is only required when you want a third party to access the ZIP file. A third party is anyone not interacting with the TrueZIP Kernel for accessing the ZIP file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im currently using a method that looks like the following code to add script
I`m currently using route53 for 2 domains that points to the same website. Lets
Currently using Chrome v19.0.1084.46 (Official Build 135956) beta-m jqGrid 4.3.2 (latest release) The problem
Im currently using base64_encode for some $_GET params that i don't want regular user
I am currently using JavaFX to display data from a SQL Server database. I
Im currently using a script (that is working) where I can apply a certain
I'm currently using http://benalman.com/projects/jquery-hashchange-plugin/ and I noticed that my hashes show up as /#page
Currently using a setup that follows: Backbone , Parse , Require , and Marionette
Currently using HtmlUnit. Getting first login page is no problem, succesfully logging in, getting
iam currently using NSURLConnection class to hit my server and get some data from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.