public OutputStream getOutputStream(DataEntry dataEntry, Finisher finisher) throws IOException { // Try to get an output stream from the first data entry writer. OutputStream outputStream = dataEntryWriter1.getOutputStream(dataEntry, finisher); // Return it, if it's not null. Otherwise try to get an output stream // from the second data entry writer. return outputStream != null ? outputStream : dataEntryWriter2.getOutputStream(dataEntry, finisher); }
public OutputStream getOutputStream(DataEntry dataEntry, Finisher finisher) throws IOException { return dataEntryWriter.getOutputStream(dataEntry.getParent(), finisher); }
public OutputStream getOutputStream(DataEntry dataEntry, Finisher finisher) throws IOException { // Get the right data entry writer. DataEntryWriter dataEntryWriter = dataEntryFilter.accepts(dataEntry) ? acceptedDataEntryWriter : rejectedDataEntryWriter; // Delegate to it, if it's not null. return dataEntryWriter != null ? dataEntryWriter.getOutputStream(dataEntry, finisher) : null; }
/** * Makes sure the current output stream is set up for the given entry. */ private boolean prepareEntry(DataEntry dataEntry) throws IOException { // Get the parent stream, new or exisiting. // This may finish our own jar output stream. OutputStream parentOutputStream = dataEntryWriter.getOutputStream(dataEntry.getParent(), this); // Did we get a stream? if (parentOutputStream == null) { return false; } // Do we need a new stream? if (currentParentOutputStream == null) { currentParentOutputStream = parentOutputStream; // Create a new jar stream, with a manifest, if set. currentJarOutputStream = manifest != null ? new JarOutputStream(parentOutputStream, manifest) : new ZipOutputStream(parentOutputStream); // Add a comment, if set. if (comment != null) { currentJarOutputStream.setComment(comment); } } return true; }
public void read(DataEntry dataEntry) throws IOException { String inputName = dataEntry.getName(); String className = inputName.substring(0, inputName.length() - ClassConstants.CLASS_FILE_EXTENSION.length()); // Find the modified class corrsponding to the input entry. ProgramClass programClass = (ProgramClass)classPool.getClass(className); if (programClass != null) { // Rename the data entry if necessary. String newClassName = programClass.getName(); if (!className.equals(newClassName)) { dataEntry = new RenamedDataEntry(dataEntry, newClassName + ClassConstants.CLASS_FILE_EXTENSION); } // Get the output entry corresponding to this input entry. OutputStream outputStream = dataEntryWriter.getOutputStream(dataEntry); if (outputStream != null) { // Write the class to the output entry. DataOutputStream classOutputStream = new DataOutputStream(outputStream); new ProgramClassWriter(classOutputStream).visitProgramClass(programClass); classOutputStream.flush(); } } } }
public void read(DataEntry dataEntry) throws IOException { try { if (dataEntry.isDirectory()) { dataEntryWriter.createDirectory(dataEntry); } else { // Get the output entry corresponding to this input entry. OutputStream outputStream = dataEntryWriter.getOutputStream(dataEntry); if (outputStream != null) { InputStream inputStream = dataEntry.getInputStream(); // Copy the data from the input entry to the output entry. copyData(inputStream, outputStream); // Close the data entries. dataEntry.closeInputStream(); } } } catch (IOException ex) { System.err.println("Warning: can't write resource [" + dataEntry.getName() + "] (" + ex.getMessage() + ")"); } }