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 8851787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:14:29+00:00 2026-06-14T13:14:29+00:00

I’m using a bytecode library known as ASM to alter classfiles, then I want

  • 0

I’m using a bytecode library known as ASM to alter classfiles, then I want to write each classfile back into a jar file rather than a folder filled with class files. I do this by running this code:

My problem occurs when a ZipException is throw for not being the expected size, i.e.

java.util.zip.ZipException: invalid entry compressed size (expected 695 but got 693 bytes)
    at java.util.zip.ZipOutputStream.closeEntry(Unknown Source)
    at org.steinburg.client.accessor.Accessor.accessJar(Accessor.java:64)
    at org.steinburg.client.accessor.Accessor.<init>(Accessor.java:41)
    at Loader.main(Loader.java:5)


package org.steinburg.client.accessor;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;

public class Accessor {

private String input;
private File inFile;
private JarEntry jarEntry;
private JarFile jarFile;
private Enumeration<JarEntry> entries;
private InputStream is;

private String out;
private File outFile;
private FileOutputStream fos;
private JarOutputStream jos;

private byte[] bytes;

public Accessor(){
    try{
        input = new String("Input Jar.jar");
        inFile = new File(input);
        jarFile = new JarFile(inFile);
        entries = jarFile.entries();
        out = new String("Output Jar.jar");
        outFile = new File(out);
        fos = new FileOutputStream(outFile);
        jos = new JarOutputStream(fos);
        accessJar();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

protected final void accessJar(){
    try {
        while (entries.hasMoreElements()){
            jarEntry = entries.nextElement();
            is = jarFile.getInputStream(jarEntry);
            if (jarEntry.getName().endsWith(".class")){
                ClassReader cr = new ClassReader(is);
                ClassWriter cw = new ClassWriter(cr, 0);
                FieldAdapter fa = new FieldAdapter(cw);
                cr.accept(fa, 0);
                bytes = cw.toByteArray();
            } else {
                bytes = readBytes(is);
            }
            JarEntry je = new JarEntry(jarEntry);
            jos.putNextEntry(je);
            jos.write(bytes);
            jos.closeEntry();
        }
        jos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

protected byte[] readBytes(InputStream inputStream){
    try{
        DataInputStream reader = new DataInputStream(inputStream);
        byte[] toReturn = new byte[reader.available()];
        reader.readFully(toReturn);
        reader.close();
        return toReturn;
    } catch (Exception e){
        e.printStackTrace();
        return null;
    }
}

}

The ClassReader, ClassWriter (each part of library), and FieldAdapter (made by myself) just altar the code, and to get the bytes of the entire class I use cw.toByteArray(). There is no problem as for the bytecode manipulation itself, it’s just the writing to a new jar file through a JarOutputStream. Anyone known how to solve this problem?

  • 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-14T13:14:30+00:00Added an answer on June 14, 2026 at 1:14 pm

    The problematic line is this:

    JarEntry je = new JarEntry(jarEntry);
    

    as it will also copy the compressed size.

    Unless you care about preserving other fields than name, you should use this constructor and provide only the file name, as this:

    JarEntry je = new JarEntry(jarEntry.getName ());
    

    The compressed size will be then automatically computed.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.