Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsliebig2007-11-15 13:10:32 +0000
committersliebig2007-11-15 13:10:32 +0000
commit95177a773ce5383740b30a7b774088c1d4a6bb2c (patch)
tree93ae3ac74178db3149696f86f1048f21e3f71cf9 /bundles/org.eclipse.equinox.p2.sar/src/org/eclipse/equinox
parent25618eb2e9f77abfe1b77474fae88c17df6bd719 (diff)
downloadrt.equinox.p2-95177a773ce5383740b30a7b774088c1d4a6bb2c.tar.gz
rt.equinox.p2-95177a773ce5383740b30a7b774088c1d4a6bb2c.tar.xz
rt.equinox.p2-95177a773ce5383740b30a7b774088c1d4a6bb2c.zip
fixes https://bugs.eclipse.org/bugs/show_bug.cgi?id=209233
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.sar/src/org/eclipse/equinox')
-rw-r--r--bundles/org.eclipse.equinox.p2.sar/src/org/eclipse/equinox/internal/p2/sar/SarEntry.java118
1 files changed, 76 insertions, 42 deletions
diff --git a/bundles/org.eclipse.equinox.p2.sar/src/org/eclipse/equinox/internal/p2/sar/SarEntry.java b/bundles/org.eclipse.equinox.p2.sar/src/org/eclipse/equinox/internal/p2/sar/SarEntry.java
index e30ff07b8..89cbd6560 100644
--- a/bundles/org.eclipse.equinox.p2.sar/src/org/eclipse/equinox/internal/p2/sar/SarEntry.java
+++ b/bundles/org.eclipse.equinox.p2.sar/src/org/eclipse/equinox/internal/p2/sar/SarEntry.java
@@ -11,17 +11,24 @@
package org.eclipse.equinox.internal.p2.sar;
import java.io.IOException;
+import java.util.Date;
import java.util.zip.ZipEntry;
/**
- * A SarEntry is the header information for an entry within a org.eclipse.equinox.p2.sar stream.
+ * A SarEntry is the header information for an entry within a
+ * org.eclipse.equinox.p2.sar stream.<br>
+ * <b>Note: </b>The setTime() and getTime() methods of ZipEntry (our super
+ * class) perform time zone dependent (!) conversions. For our serialization and
+ * deserialization the stored time has to be time zone neutral. Therefore it is
+ * necessary to invert those calculations. This is also the reason for
+ * duplicating the javaToDosTime() and dosToJavaTime() methods.
*/
public class SarEntry extends ZipEntry {
private boolean isEof;
private boolean isZip;
- /**
+ /**
* The name of the eof org.eclipse.equinox.p2.sar entry.
*/
private static final String EOF_ENTRY_NAME = "<eof-org.eclipse.equinox.p2.sar>";
@@ -32,8 +39,8 @@ public class SarEntry extends ZipEntry {
* Creates an eof org.eclipse.equinox.p2.sar entry
*/
public SarEntry() {
- super( EOF_ENTRY_NAME );
- setMethod( ZipEntry.DEFLATED );
+ super(EOF_ENTRY_NAME);
+ setMethod(ZipEntry.DEFLATED);
this.isEof = true;
this.isZip = false;
}
@@ -41,8 +48,8 @@ public class SarEntry extends ZipEntry {
/**
* @param zipEntry
*/
- public SarEntry( ZipEntry zipEntry ) {
- super( zipEntry );
+ public SarEntry(ZipEntry zipEntry) {
+ super(zipEntry);
this.isZip = false;
this.isEof = false;
}
@@ -51,8 +58,8 @@ public class SarEntry extends ZipEntry {
* @param zipEntry
* @param isZip
*/
- public SarEntry( ZipEntry zipEntry, boolean isZip ) {
- super( zipEntry );
+ public SarEntry(ZipEntry zipEntry, boolean isZip) {
+ super(zipEntry);
this.isZip = isZip;
this.isEof = false;
}
@@ -61,9 +68,9 @@ public class SarEntry extends ZipEntry {
* @param sarInputStream
* @throws IOException
*/
- public SarEntry( SarInputStream sarInputStream ) throws IOException {
+ public SarEntry(SarInputStream sarInputStream) throws IOException {
// read name!
- super( sarInputStream.readString() );
+ super(sarInputStream.readString());
String comment = sarInputStream.readString();
long compressedSize = sarInputStream.readLong();
@@ -71,34 +78,35 @@ public class SarEntry extends ZipEntry {
byte[] extra = sarInputStream.readBytes();
int method = sarInputStream.readInt();
long size = sarInputStream.readLong();
- long time = sarInputStream.readLong();
+ long dosTime = sarInputStream.readLong();
boolean isEof = sarInputStream.readBoolean();
boolean isZip = sarInputStream.readBoolean();
- if ( DEBUG ) {
- System.out.println( getName() + "," + comment + "," + compressedSize + "," + crc + "," + extra + "," + method + "," + size + "," + time + ","
- + isEof + "," + isZip );
+ if (DEBUG) {
+ System.out.println(getName() + "," + comment + "," + compressedSize
+ + "," + crc + "," + extra + "," + method + "," + size + ","
+ + dosTime + "," + isEof + "," + isZip);
}
- if ( method == ZipEntry.STORED ) {
- setCompressedSize( compressedSize );
- setCrc( crc );
- setSize( size );
+ if (method == ZipEntry.STORED) {
+ setCompressedSize(compressedSize);
+ setCrc(crc);
+ setSize(size);
}
- setComment( comment );
- setExtra( extra );
- setMethod( method );
- setTime( time );
- setEof( isEof );
- setZip( isZip );
+ setComment(comment);
+ setExtra(extra);
+ setMethod(method);
+ setTime(dosToJavaTime(dosTime));
+ setEof(isEof);
+ setZip(isZip);
}
/**
* @param sarOutputStream
* @throws IOException
*/
- public void writeTo( SarOutputStream sarOutputStream ) throws IOException {
+ public void writeTo(SarOutputStream sarOutputStream) throws IOException {
String comment = this.getComment();
long compressedSize = this.getCompressedSize();
long crc = this.getCrc();
@@ -106,37 +114,38 @@ public class SarEntry extends ZipEntry {
int method = this.getMethod();
String name = this.getName();
long size = this.getSize();
- long time = this.getTime();
+ long dosTime = javaToDosTime(this.getTime());
boolean isZip = this.isZip();
boolean isEof = this.isEof();
- if ( DEBUG ) {
- System.out.println( name + "," + comment + "," + compressedSize + "," + crc + "," + extra + "," + method + "," + size + "," + time + "," + isEof
- + "," + isZip );
+ if (DEBUG) {
+ System.out.println(name + "," + comment + "," + compressedSize
+ + "," + crc + "," + extra + "," + method + "," + size + ","
+ + dosTime + "," + isEof + "," + isZip);
}
- sarOutputStream.writeString( name );
- sarOutputStream.writeString( comment );
- sarOutputStream.writeLong( compressedSize );
- sarOutputStream.writeLong( crc );
- sarOutputStream.writeBytes( extra );
- sarOutputStream.writeInt( method );
- sarOutputStream.writeLong( size );
- sarOutputStream.writeLong( time );
- sarOutputStream.writeBool( isEof );
- sarOutputStream.writeBool( isZip );
+ sarOutputStream.writeString(name);
+ sarOutputStream.writeString(comment);
+ sarOutputStream.writeLong(compressedSize);
+ sarOutputStream.writeLong(crc);
+ sarOutputStream.writeBytes(extra);
+ sarOutputStream.writeInt(method);
+ sarOutputStream.writeLong(size);
+ sarOutputStream.writeLong(dosTime);
+ sarOutputStream.writeBool(isEof);
+ sarOutputStream.writeBool(isZip);
}
/**
* Is this the eof org.eclipse.equinox.p2.sar entry?
*
- * @return the answer
+ * @return the answer
*/
public boolean isEof() {
return isEof;
}
- private void setEof( boolean isEof ) {
+ private void setEof(boolean isEof) {
this.isEof = isEof;
}
@@ -150,8 +159,33 @@ public class SarEntry extends ZipEntry {
/**
* @param isZip
*/
- private void setZip( boolean isZip ) {
+ private void setZip(boolean isZip) {
this.isZip = isZip;
}
+ /*
+ * Converts DOS time to Java time (number of milliseconds since epoch).
+ */
+ public final static long dosToJavaTime(long dtime) {
+ Date d = new Date((int) (((dtime >> 25) & 0x7f) + 80),
+ (int) (((dtime >> 21) & 0x0f) - 1),
+ (int) ((dtime >> 16) & 0x1f), (int) ((dtime >> 11) & 0x1f),
+ (int) ((dtime >> 5) & 0x3f), (int) ((dtime << 1) & 0x3e));
+ return d.getTime();
+ }
+
+ /*
+ * Converts Java time to DOS time.
+ */
+ public final static long javaToDosTime(long time) {
+ Date d = new Date(time);
+ int year = d.getYear() + 1900;
+ if (year < 1980) {
+ return (1 << 21) | (1 << 16);
+ }
+ return (year - 1980) << 25 | (d.getMonth() + 1) << 21
+ | d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5
+ | d.getSeconds() >> 1;
+ }
+
}

Back to the top