Skip to content

Commit e45b389

Browse files
author
Dmitry Pelevin
committed
PLXCOMP-222 LEF flag set for UTF-8 encoded names.
1 parent d8ea9b5 commit e45b389

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

src/main/java/org/codehaus/plexus/archiver/zip/ZipOutputStream.java

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.OutputStream;
2525
import java.io.RandomAccessFile;
2626
import java.io.UnsupportedEncodingException;
27+
import java.nio.charset.Charset;
2728
import java.util.Date;
2829
import java.util.Hashtable;
2930
import java.util.Vector;
@@ -206,6 +207,13 @@ public class ZipOutputStream
206207
*/
207208
private RandomAccessFile raf = null;
208209

210+
/**
211+
* UTF-8 encoding name.
212+
*
213+
* @since 2.4.5
214+
*/
215+
private static final String UTF8 = "UTF-8";
216+
209217
/**
210218
* Compression method for deflated entries.
211219
*
@@ -607,6 +615,8 @@ public void flush()
607615
static final byte[] Z20_bytes = ZipShort.bytes( 20 );
608616
static final byte[] Z8_bytes = ZipShort.bytes( 8 );
609617
static final byte[] Z10_bytes = ZipShort.bytes( 10 );
618+
static final byte[] Z2048_bytes = ZipShort.bytes( 2048 );
619+
static final byte[] Z2056_bytes = ZipShort.bytes( 2056 );
610620
static final byte[] LFH_SIG_bytes = LFH_SIG.getBytes();
611621
static final byte[] DD_SIG_bytes = DD_SIG.getBytes();
612622
static final byte[] CFH_SIG_bytes = CFH_SIG.getBytes();
@@ -650,12 +660,26 @@ protected void writeLocalFileHeader( ZipEntry ze )
650660
writeOut( Z20_bytes );
651661

652662
// bit3 set to signal, we use a data descriptor
653-
writeOut( Z8_bytes );
663+
if ( isLefRequired() )
664+
{
665+
writeOut(Z2056_bytes);
666+
}
667+
else
668+
{
669+
writeOut(Z8_bytes);
670+
}
654671
}
655672
else
656673
{
657674
writeOut( Z10_bytes );
658-
writeOut( ZERO );
675+
if ( isLefRequired() )
676+
{
677+
writeOut(Z2048_bytes);
678+
}
679+
else
680+
{
681+
writeOut(ZERO);
682+
}
659683
}
660684
written += 4;
661685

@@ -749,12 +773,26 @@ protected void writeCentralFileHeader( ZipEntry ze )
749773
writeOut( Z20_bytes );
750774

751775
// bit3 set to signal, we use a data descriptor
752-
writeOut( Z8_bytes );
776+
if ( isLefRequired() )
777+
{
778+
writeOut( Z2056_bytes );
779+
}
780+
else
781+
{
782+
writeOut( Z8_bytes );
783+
}
753784
}
754785
else
755786
{
756787
writeOut( Z10_bytes );
757-
writeOut( ZERO );
788+
if ( isLefRequired() )
789+
{
790+
writeOut( Z2048_bytes );
791+
}
792+
else
793+
{
794+
writeOut( ZERO );
795+
}
758796
}
759797
written += 4;
760798

@@ -955,4 +993,11 @@ final byte[] longBytes(long value)
955993
{
956994
return ZipLong.bytes(value, longBuffer);
957995
}
996+
997+
private boolean isLefRequired() {
998+
return encoding == null
999+
&& UTF8.equals(Charset.defaultCharset().name())
1000+
|| (encoding != null && UTF8.equals(encoding));
1001+
}
1002+
9581003
}

0 commit comments

Comments
 (0)