You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gr...@apache.org on 2009/04/27 19:58:04 UTC
svn commit: r769070 - in
/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers:
ar/ArArchiveOutputStream.java cpio/CpioArchiveOutputStream.java
tar/TarArchiveOutputStream.java zip/ZipArchiveOutputStream.java
Author: grobmeier
Date: Mon Apr 27 17:58:04 2009
New Revision: 769070
URL: http://svn.apache.org/viewvc?rev=769070&view=rev
Log:
only write and close is allowed after the call of finish
Modified:
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java?rev=769070&r1=769069&r2=769070&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java Mon Apr 27 17:58:04 2009
@@ -53,6 +53,9 @@
}
public void closeArchiveEntry() throws IOException {
+ if(finished) {
+ throw new IOException("Stream has already been finished");
+ }
if (prevEntry != null && haveUnclosedEntry && (entryOffset % 2) != 0) {
out.write('\n'); // Pad byte
archiveOffset++;
@@ -61,6 +64,10 @@
}
public void putArchiveEntry( final ArchiveEntry pEntry ) throws IOException {
+ if(finished) {
+ throw new IOException("Stream has already been finished");
+ }
+
ArArchiveEntry pArEntry = (ArArchiveEntry)pEntry;
if (prevEntry == null) {
archiveOffset += writeArchiveHeader();
@@ -166,6 +173,9 @@
public ArchiveEntry createArchiveEntry(File inputFile, String entryName)
throws IOException {
+ if(finished) {
+ throw new IOException("Stream has already been finished");
+ }
return new ArArchiveEntry(inputFile, entryName);
}
Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java?rev=769070&r1=769069&r2=769070&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java Mon Apr 27 17:58:04 2009
@@ -143,6 +143,10 @@
* @throws ClassCastException if entry is not an instance of CpioArchiveEntry
*/
public void putArchiveEntry(ArchiveEntry entry) throws IOException {
+ if(finished) {
+ throw new IOException("Stream has already been finished");
+ }
+
CpioArchiveEntry e = (CpioArchiveEntry) entry;
ensureOpen();
if (this.entry != null) {
@@ -244,6 +248,10 @@
* ()
*/
public void closeArchiveEntry() throws IOException {
+ if(finished) {
+ throw new IOException("Stream has already been finished");
+ }
+
ensureOpen();
if (this.entry.getSize() != this.written) {
@@ -400,6 +408,9 @@
*/
public ArchiveEntry createArchiveEntry(File inputFile, String entryName)
throws IOException {
+ if(finished) {
+ throw new IOException("Stream has already been finished");
+ }
return new CpioArchiveEntry(inputFile, entryName);
}
Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java?rev=769070&r1=769069&r2=769070&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java Mon Apr 27 17:58:04 2009
@@ -165,6 +165,9 @@
* @throws ClassCastException if archiveEntry is not an instance of TarArchiveEntry
*/
public void putArchiveEntry(ArchiveEntry archiveEntry) throws IOException {
+ if(finished) {
+ throw new IOException("Stream has already been finished");
+ }
TarArchiveEntry entry = (TarArchiveEntry) archiveEntry;
if (entry.getName().length() >= TarConstants.NAMELEN) {
@@ -212,6 +215,9 @@
* @throws IOException on error
*/
public void closeArchiveEntry() throws IOException {
+ if(finished) {
+ throw new IOException("Stream has already been finished");
+ }
if (assemLen > 0) {
for (int i = assemLen; i < assemBuf.length; ++i) {
assemBuf[i] = 0;
@@ -332,6 +338,9 @@
public ArchiveEntry createArchiveEntry(File inputFile, String entryName)
throws IOException {
+ if(finished) {
+ throw new IOException("Stream has already been finished");
+ }
return new TarArchiveEntry(inputFile, entryName);
}
}
Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java?rev=769070&r1=769069&r2=769070&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java Mon Apr 27 17:58:04 2009
@@ -62,8 +62,8 @@
private static final int WORD = 4;
static final int BUFFER_SIZE = 512;
- /** indicates if this archive is finished */
- private boolean finished = false;
+ /** indicates if this archive is finished. protected for use in Jar implementation */
+ protected boolean finished = false;
/*
* Apparently Deflater.setInput gets slowed down a lot on Sun JVMs
@@ -227,8 +227,7 @@
/**
* whether to create UnicodePathExtraField-s for each entry.
*/
- private UnicodeExtraFieldPolicy createUnicodeExtraFields =
- UnicodeExtraFieldPolicy.NEVER;
+ private UnicodeExtraFieldPolicy createUnicodeExtraFields = UnicodeExtraFieldPolicy.NEVER;
/**
* Creates a new ZIP OutputStream filtering the underlying stream.
@@ -360,6 +359,10 @@
* @throws IOException on error
*/
public void closeArchiveEntry() throws IOException {
+ if(finished) {
+ throw new IOException("Stream has already been finished");
+ }
+
if (entry == null) {
return;
}
@@ -423,6 +426,10 @@
/** {@inheritDoc} */
// @throws ClassCastException if entry is not an instance of ZipArchiveEntry
public void putArchiveEntry(ArchiveEntry archiveEntry) throws IOException {
+ if(finished) {
+ throw new IOException("Stream has already been finished");
+ }
+
closeArchiveEntry();
entry = ((ZipArchiveEntry) archiveEntry);
@@ -901,13 +908,11 @@
/**
* Always create Unicode extra fields.
*/
- public static final UnicodeExtraFieldPolicy ALWAYS =
- new UnicodeExtraFieldPolicy("always");
+ public static final UnicodeExtraFieldPolicy ALWAYS = new UnicodeExtraFieldPolicy("always");
/**
* Never create Unicode extra fields.
*/
- public static final UnicodeExtraFieldPolicy NEVER =
- new UnicodeExtraFieldPolicy("never");
+ public static final UnicodeExtraFieldPolicy NEVER = new UnicodeExtraFieldPolicy("never");
/**
* Create Unicode extra fields for filenames that cannot be
* encoded using the specified encoding.
@@ -926,6 +931,9 @@
public ArchiveEntry createArchiveEntry(File inputFile, String entryName)
throws IOException {
+ if(finished) {
+ throw new IOException("Stream has already been finished");
+ }
return new ZipArchiveEntry(inputFile, entryName);
}
}