mirror of
https://github.com/AppleCommander/ShrinkItArchive.git
synced 2024-12-22 02:31:00 +00:00
Switched ByteSource to be an InputStream; renamed ByteSource LittleEndianByteInputStream.
This commit is contained in:
parent
ec9c833f58
commit
0511fbfce5
@ -5,6 +5,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.webcodepro.shrinkit.io.LittleEndianByteInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Header Block contains information and content
|
* The Header Block contains information and content
|
||||||
* about a single entry (be it a file or disk image).
|
* about a single entry (be it a file or disk image).
|
||||||
@ -40,7 +42,7 @@ public class HeaderBlock {
|
|||||||
* Create the Header Block. This is done dynamically since
|
* Create the Header Block. This is done dynamically since
|
||||||
* the Header Block size varies significantly.
|
* the Header Block size varies significantly.
|
||||||
*/
|
*/
|
||||||
public HeaderBlock(ByteSource bs) throws IOException {
|
public HeaderBlock(LittleEndianByteInputStream bs) throws IOException {
|
||||||
bs.checkNuFxId();
|
bs.checkNuFxId();
|
||||||
headerCrc = bs.readWord();
|
headerCrc = bs.readWord();
|
||||||
attribCount = bs.readWord();
|
attribCount = bs.readWord();
|
||||||
@ -81,7 +83,7 @@ public class HeaderBlock {
|
|||||||
* Read in all data threads. All ThreadRecords are read and then
|
* Read in all data threads. All ThreadRecords are read and then
|
||||||
* each thread's data is read (per NuFX spec).
|
* each thread's data is read (per NuFX spec).
|
||||||
*/
|
*/
|
||||||
public void readThreads(ByteSource bs) throws IOException {
|
public void readThreads(LittleEndianByteInputStream bs) throws IOException {
|
||||||
threads = new ArrayList<ThreadRecord>();
|
threads = new ArrayList<ThreadRecord>();
|
||||||
for (long l=0; l<totalThreads; l++) threads.add(new ThreadRecord(bs));
|
for (long l=0; l<totalThreads; l++) threads.add(new ThreadRecord(bs));
|
||||||
for (ThreadRecord r : threads) r.readThreadData(bs);
|
for (ThreadRecord r : threads) r.readThreadData(bs);
|
||||||
|
@ -3,6 +3,8 @@ package com.webcodepro.shrinkit;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import com.webcodepro.shrinkit.io.LittleEndianByteInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Master Header Block contains information about the entire
|
* The Master Header Block contains information about the entire
|
||||||
* ShrinkIt archive.
|
* ShrinkIt archive.
|
||||||
@ -25,9 +27,9 @@ public class MasterHeaderBlock {
|
|||||||
private long masterEof;
|
private long masterEof;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the Master Header Block, based on the ByteSource.
|
* Create the Master Header Block, based on the LittleEndianByteInputStream.
|
||||||
*/
|
*/
|
||||||
public MasterHeaderBlock(ByteSource bs) throws IOException {
|
public MasterHeaderBlock(LittleEndianByteInputStream bs) throws IOException {
|
||||||
bs.checkNuFileId();
|
bs.checkNuFileId();
|
||||||
masterCrc = bs.readWord();
|
masterCrc = bs.readWord();
|
||||||
bs.resetCrc(); // CRC is computed from this point to the end of the header
|
bs.resetCrc(); // CRC is computed from this point to the end of the header
|
||||||
|
@ -5,6 +5,8 @@ import java.io.InputStream;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.webcodepro.shrinkit.io.LittleEndianByteInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic reading of a NuFX archive.
|
* Basic reading of a NuFX archive.
|
||||||
*
|
*
|
||||||
@ -18,7 +20,7 @@ public class NuFileArchive {
|
|||||||
* Read in the NuFile/NuFX/Shrinkit archive.
|
* Read in the NuFile/NuFX/Shrinkit archive.
|
||||||
*/
|
*/
|
||||||
public NuFileArchive(InputStream inputStream) throws IOException {
|
public NuFileArchive(InputStream inputStream) throws IOException {
|
||||||
ByteSource bs = new ByteSource(inputStream);
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream(inputStream);
|
||||||
master = new MasterHeaderBlock(bs);
|
master = new MasterHeaderBlock(bs);
|
||||||
headers = new ArrayList<HeaderBlock>();
|
headers = new ArrayList<HeaderBlock>();
|
||||||
for (int i=0; i<master.getTotalRecords(); i++) {
|
for (int i=0; i<master.getTotalRecords(); i++) {
|
||||||
|
@ -4,6 +4,8 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import com.webcodepro.shrinkit.io.LittleEndianByteInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This represents a single thread from the Shrinkit archive.
|
* This represents a single thread from the Shrinkit archive.
|
||||||
* As it is constructed, the thread "header" is read. Once all
|
* As it is constructed, the thread "header" is read. Once all
|
||||||
@ -29,7 +31,7 @@ public class ThreadRecord {
|
|||||||
/**
|
/**
|
||||||
* Construct the ThreadRecord and read the header details.
|
* Construct the ThreadRecord and read the header details.
|
||||||
*/
|
*/
|
||||||
public ThreadRecord(ByteSource bs) throws IOException {
|
public ThreadRecord(LittleEndianByteInputStream bs) throws IOException {
|
||||||
threadClass = ThreadClass.find(bs.readWord());
|
threadClass = ThreadClass.find(bs.readWord());
|
||||||
threadFormat = ThreadFormat.find(bs.readWord());
|
threadFormat = ThreadFormat.find(bs.readWord());
|
||||||
threadKind = ThreadKind.find(bs.readWord(), threadClass);
|
threadKind = ThreadKind.find(bs.readWord(), threadClass);
|
||||||
@ -41,7 +43,7 @@ public class ThreadRecord {
|
|||||||
/**
|
/**
|
||||||
* Read the raw thread data. This must be called.
|
* Read the raw thread data. This must be called.
|
||||||
*/
|
*/
|
||||||
public void readThreadData(ByteSource bs) throws IOException {
|
public void readThreadData(LittleEndianByteInputStream bs) throws IOException {
|
||||||
threadData = bs.readBytes((int)compThreadEof);
|
threadData = bs.readBytes((int)compThreadEof);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package com.webcodepro.shrinkit;
|
package com.webcodepro.shrinkit.io;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides constants for the ByteSource and ByteTarget classes.
|
* Provides constants for the LittleEndianByteInputStream and ByteTarget classes.
|
||||||
*
|
*
|
||||||
* @author robgreene@users.sourceforge.net
|
* @author robgreene@users.sourceforge.net
|
||||||
* @see ByteSource
|
* @see LittleEndianByteInputStream
|
||||||
* @see ByteTarget
|
* @see ByteTarget
|
||||||
*/
|
*/
|
||||||
public interface ByteConstants {
|
public interface ByteConstants {
|
@ -1,4 +1,4 @@
|
|||||||
package com.webcodepro.shrinkit;
|
package com.webcodepro.shrinkit.io;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -7,25 +7,27 @@ import java.util.Arrays;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
|
import com.webcodepro.shrinkit.CRC16;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple class to hide the source of byte data.
|
* A simple class to hide the source of byte data.
|
||||||
* @author robgreene@users.sourceforge.net
|
* @author robgreene@users.sourceforge.net
|
||||||
*/
|
*/
|
||||||
public class ByteSource implements ByteConstants {
|
public class LittleEndianByteInputStream extends InputStream implements ByteConstants {
|
||||||
private InputStream inputStream;
|
private InputStream inputStream;
|
||||||
private long bytesRead = 0;
|
private long bytesRead = 0;
|
||||||
private CRC16 crc = new CRC16();
|
private CRC16 crc = new CRC16();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a ByteSource from an InputStream.
|
* Construct a LittleEndianByteInputStream from an InputStream.
|
||||||
*/
|
*/
|
||||||
public ByteSource(InputStream inputStream) {
|
public LittleEndianByteInputStream(InputStream inputStream) {
|
||||||
this.inputStream = inputStream;
|
this.inputStream = inputStream;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Construct a ByteSource from a byte array.
|
* Construct a LittleEndianByteInputStream from a byte array.
|
||||||
*/
|
*/
|
||||||
public ByteSource(byte[] data) {
|
public LittleEndianByteInputStream(byte[] data) {
|
||||||
this.inputStream = new ByteArrayInputStream(data);
|
this.inputStream = new ByteArrayInputStream(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,14 +69,14 @@ public class ByteSource implements ByteConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that the NuFile id is embedded in the ByteSource.
|
* Test that the NuFile id is embedded in the LittleEndianByteInputStream.
|
||||||
*/
|
*/
|
||||||
public boolean checkNuFileId() throws IOException {
|
public boolean checkNuFileId() throws IOException {
|
||||||
byte[] data = readBytes(6);
|
byte[] data = readBytes(6);
|
||||||
return Arrays.equals(data, NUFILE_ID);
|
return Arrays.equals(data, NUFILE_ID);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Test that the NuFx id is embedded in the ByteSource.
|
* Test that the NuFx id is embedded in the LittleEndianByteInputStream.
|
||||||
*/
|
*/
|
||||||
public boolean checkNuFxId() throws IOException {
|
public boolean checkNuFxId() throws IOException {
|
||||||
byte[] data = readBytes(4);
|
byte[] data = readBytes(4);
|
@ -3,7 +3,6 @@ package com.webcodepro.shrinkit.io;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import com.webcodepro.shrinkit.ByteSource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The RleInputStream handles the NuFX RLE data stream.
|
* The RleInputStream handles the NuFX RLE data stream.
|
||||||
@ -15,7 +14,7 @@ import com.webcodepro.shrinkit.ByteSource;
|
|||||||
* @author robgreene@users.sourceforge.net
|
* @author robgreene@users.sourceforge.net
|
||||||
*/
|
*/
|
||||||
public class RleInputStream extends InputStream {
|
public class RleInputStream extends InputStream {
|
||||||
private ByteSource bs;
|
private LittleEndianByteInputStream bs;
|
||||||
private int escapeChar;
|
private int escapeChar;
|
||||||
private int repeatedByte;
|
private int repeatedByte;
|
||||||
private int numBytes = -1;
|
private int numBytes = -1;
|
||||||
@ -23,13 +22,13 @@ public class RleInputStream extends InputStream {
|
|||||||
/**
|
/**
|
||||||
* Create an RLE input stream with the default marker byte.
|
* Create an RLE input stream with the default marker byte.
|
||||||
*/
|
*/
|
||||||
public RleInputStream(ByteSource bs) {
|
public RleInputStream(LittleEndianByteInputStream bs) {
|
||||||
this(bs, 0xdb);
|
this(bs, 0xdb);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Create an RLE input stream with the specified marker byte.
|
* Create an RLE input stream with the specified marker byte.
|
||||||
*/
|
*/
|
||||||
public RleInputStream(ByteSource bs, int escapeChar) {
|
public RleInputStream(LittleEndianByteInputStream bs, int escapeChar) {
|
||||||
this.bs = bs;
|
this.bs = bs;
|
||||||
this.escapeChar = escapeChar;
|
this.escapeChar = escapeChar;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ package com.webcodepro.shrinkit;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import com.webcodepro.shrinkit.io.LittleEndianByteInputStream;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,7 +27,7 @@ public class HeaderBlockTest extends TestCase {
|
|||||||
0x00, 0x0c, 0x01, 0x58, 0x16, 0x0a, 0x00, 0x07,
|
0x00, 0x0c, 0x01, 0x58, 0x16, 0x0a, 0x00, 0x07,
|
||||||
0x05, 0x00, 0x53, 0x54, 0x55, 0x46, 0x46
|
0x05, 0x00, 0x53, 0x54, 0x55, 0x46, 0x46
|
||||||
};
|
};
|
||||||
ByteSource bs = new ByteSource(data);
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream(data);
|
||||||
HeaderBlock b = new HeaderBlock(bs);
|
HeaderBlock b = new HeaderBlock(bs);
|
||||||
assertEquals(0x3455, b.getHeaderCrc());
|
assertEquals(0x3455, b.getHeaderCrc());
|
||||||
assertEquals(0x003a, b.getAttribCount());
|
assertEquals(0x003a, b.getAttribCount());
|
||||||
@ -37,9 +39,9 @@ public class HeaderBlockTest extends TestCase {
|
|||||||
assertEquals(0x00000004, b.getFileType());
|
assertEquals(0x00000004, b.getFileType());
|
||||||
assertEquals(0x00000000, b.getExtraType());
|
assertEquals(0x00000000, b.getExtraType());
|
||||||
assertEquals(0x0001, b.getStorageType());
|
assertEquals(0x0001, b.getStorageType());
|
||||||
assertEquals(new ByteSource(new byte[] {0x00,0x0a,0x01,0x58,0x16,0x0a,0x00,0x07}).readDate(), b.getCreateWhen());
|
assertEquals(new LittleEndianByteInputStream(new byte[] {0x00,0x0a,0x01,0x58,0x16,0x0a,0x00,0x07}).readDate(), b.getCreateWhen());
|
||||||
assertEquals(new ByteSource(new byte[] {0x00,0x10,0x0b,0x58,0x11,0x0b,0x00,0x05}).readDate(), b.getModWhen());
|
assertEquals(new LittleEndianByteInputStream(new byte[] {0x00,0x10,0x0b,0x58,0x11,0x0b,0x00,0x05}).readDate(), b.getModWhen());
|
||||||
assertEquals(new ByteSource(new byte[] {0x00,0x0c,0x01,0x58,0x16,0x0a,0x00,0x07}).readDate(), b.getArchiveWhen());
|
assertEquals(new LittleEndianByteInputStream(new byte[] {0x00,0x0c,0x01,0x58,0x16,0x0a,0x00,0x07}).readDate(), b.getArchiveWhen());
|
||||||
assertEquals("STUFF", b.getFilename());
|
assertEquals("STUFF", b.getFilename());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +60,7 @@ public class HeaderBlockTest extends TestCase {
|
|||||||
0x09, 0x00, 0x45, 0x58, 0x54, 0x2e, 0x53, 0x54,
|
0x09, 0x00, 0x45, 0x58, 0x54, 0x2e, 0x53, 0x54,
|
||||||
0x55, 0x46, 0x46
|
0x55, 0x46, 0x46
|
||||||
};
|
};
|
||||||
ByteSource bs = new ByteSource(data);
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream(data);
|
||||||
HeaderBlock b = new HeaderBlock(bs);
|
HeaderBlock b = new HeaderBlock(bs);
|
||||||
assertEquals(0x7865, b.getHeaderCrc());
|
assertEquals(0x7865, b.getHeaderCrc());
|
||||||
assertEquals(0x003a, b.getAttribCount());
|
assertEquals(0x003a, b.getAttribCount());
|
||||||
@ -70,9 +72,9 @@ public class HeaderBlockTest extends TestCase {
|
|||||||
assertEquals(0x000000b3, b.getFileType());
|
assertEquals(0x000000b3, b.getFileType());
|
||||||
assertEquals(0x00000000, b.getExtraType());
|
assertEquals(0x00000000, b.getExtraType());
|
||||||
assertEquals(0x0005, b.getStorageType());
|
assertEquals(0x0005, b.getStorageType());
|
||||||
assertEquals(new ByteSource(new byte[] {0x00,0x0a,0x01,0x58,0x16,0x0a,0x00,0x07}).readDate(), b.getCreateWhen());
|
assertEquals(new LittleEndianByteInputStream(new byte[] {0x00,0x0a,0x01,0x58,0x16,0x0a,0x00,0x07}).readDate(), b.getCreateWhen());
|
||||||
assertEquals(new ByteSource(new byte[] {0x00,0x10,0x0b,0x58,0x11,0x0b,0x00,0x05}).readDate(), b.getModWhen());
|
assertEquals(new LittleEndianByteInputStream(new byte[] {0x00,0x10,0x0b,0x58,0x11,0x0b,0x00,0x05}).readDate(), b.getModWhen());
|
||||||
assertEquals(new ByteSource(new byte[] {0x00,0x0c,0x01,0x58,0x16,0x0a,0x00,0x07}).readDate(), b.getArchiveWhen());
|
assertEquals(new LittleEndianByteInputStream(new byte[] {0x00,0x0c,0x01,0x58,0x16,0x0a,0x00,0x07}).readDate(), b.getArchiveWhen());
|
||||||
assertEquals("EXT.STUFF", b.getFilename());
|
assertEquals("EXT.STUFF", b.getFilename());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +92,7 @@ public class HeaderBlockTest extends TestCase {
|
|||||||
0x00, 0x0c, 0x01, 0x58, 0x16, 0x0a, 0x00, 0x07,
|
0x00, 0x0c, 0x01, 0x58, 0x16, 0x0a, 0x00, 0x07,
|
||||||
0x04, 0x00, 0x44, 0x49, 0x53, 0x4b
|
0x04, 0x00, 0x44, 0x49, 0x53, 0x4b
|
||||||
};
|
};
|
||||||
ByteSource bs = new ByteSource(data);
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream(data);
|
||||||
HeaderBlock b = new HeaderBlock(bs);
|
HeaderBlock b = new HeaderBlock(bs);
|
||||||
assertEquals(0x0567, b.getHeaderCrc());
|
assertEquals(0x0567, b.getHeaderCrc());
|
||||||
assertEquals(0x003a, b.getAttribCount());
|
assertEquals(0x003a, b.getAttribCount());
|
||||||
@ -102,9 +104,9 @@ public class HeaderBlockTest extends TestCase {
|
|||||||
assertEquals(0x00000000, b.getFileType());
|
assertEquals(0x00000000, b.getFileType());
|
||||||
assertEquals(0x00000640, b.getExtraType());
|
assertEquals(0x00000640, b.getExtraType());
|
||||||
assertEquals(0x0200, b.getStorageType());
|
assertEquals(0x0200, b.getStorageType());
|
||||||
assertEquals(new ByteSource(new byte[] {0x00,0x0a,0x01,0x58,0x16,0x0a,0x00,0x07}).readDate(), b.getCreateWhen());
|
assertEquals(new LittleEndianByteInputStream(new byte[] {0x00,0x0a,0x01,0x58,0x16,0x0a,0x00,0x07}).readDate(), b.getCreateWhen());
|
||||||
assertEquals(new ByteSource(new byte[] {0x00,0x10,0x0b,0x58,0x11,0x0b,0x00,0x05}).readDate(), b.getModWhen());
|
assertEquals(new LittleEndianByteInputStream(new byte[] {0x00,0x10,0x0b,0x58,0x11,0x0b,0x00,0x05}).readDate(), b.getModWhen());
|
||||||
assertEquals(new ByteSource(new byte[] {0x00,0x0c,0x01,0x58,0x16,0x0a,0x00,0x07}).readDate(), b.getArchiveWhen());
|
assertEquals(new LittleEndianByteInputStream(new byte[] {0x00,0x0c,0x01,0x58,0x16,0x0a,0x00,0x07}).readDate(), b.getArchiveWhen());
|
||||||
assertEquals("DISK", b.getFilename());
|
assertEquals("DISK", b.getFilename());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +125,7 @@ public class HeaderBlockTest extends TestCase {
|
|||||||
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00
|
0x00, 0x00, 0x00, 0x00
|
||||||
};
|
};
|
||||||
ByteSource bs = new ByteSource(data);
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream(data);
|
||||||
HeaderBlock b = new HeaderBlock(bs);
|
HeaderBlock b = new HeaderBlock(bs);
|
||||||
assertEquals(0x405e, b.getHeaderCrc());
|
assertEquals(0x405e, b.getHeaderCrc());
|
||||||
assertEquals(0x003c, b.getAttribCount());
|
assertEquals(0x003c, b.getAttribCount());
|
||||||
@ -135,9 +137,9 @@ public class HeaderBlockTest extends TestCase {
|
|||||||
assertEquals(0x000000b0, b.getFileType());
|
assertEquals(0x000000b0, b.getFileType());
|
||||||
assertEquals(0x00000003, b.getExtraType());
|
assertEquals(0x00000003, b.getExtraType());
|
||||||
assertEquals(0x0002, b.getStorageType());
|
assertEquals(0x0002, b.getStorageType());
|
||||||
assertEquals(new ByteSource(new byte[] {0x00,0x1c,0x10,0x5d,0x1c,0x06,0x00,0x05}).readDate(), b.getCreateWhen());
|
assertEquals(new LittleEndianByteInputStream(new byte[] {0x00,0x1c,0x10,0x5d,0x1c,0x06,0x00,0x05}).readDate(), b.getCreateWhen());
|
||||||
assertEquals(new ByteSource(new byte[] {0x00,0x11,0x11,0x5e,0x13,0x01,0x00,0x01}).readDate(), b.getModWhen());
|
assertEquals(new LittleEndianByteInputStream(new byte[] {0x00,0x11,0x11,0x5e,0x13,0x01,0x00,0x01}).readDate(), b.getModWhen());
|
||||||
assertEquals(new ByteSource(new byte[] {0x38,0x0c,0x14,0x5f,0x08,0x07,0x00,0x04}).readDate(), b.getArchiveWhen());
|
assertEquals(new LittleEndianByteInputStream(new byte[] {0x38,0x0c,0x14,0x5f,0x08,0x07,0x00,0x04}).readDate(), b.getArchiveWhen());
|
||||||
assertEquals(0x0000, b.getOptionSize());
|
assertEquals(0x0000, b.getOptionSize());
|
||||||
assertNull(b.getFilename());
|
assertNull(b.getFilename());
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ package com.webcodepro.shrinkit;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import com.webcodepro.shrinkit.io.LittleEndianByteInputStream;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,7 +14,7 @@ import junit.framework.TestCase;
|
|||||||
*/
|
*/
|
||||||
public class MasterHeaderBlockTest extends TestCase {
|
public class MasterHeaderBlockTest extends TestCase {
|
||||||
public void testWithValidCrc() throws IOException {
|
public void testWithValidCrc() throws IOException {
|
||||||
ByteSource bs = new ByteSource(new byte[] {
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream(new byte[] {
|
||||||
0x4e, (byte)0xf5, 0x46, (byte)0xe9, 0x6c, (byte)0xe5, (byte)0xdc, 0x1b,
|
0x4e, (byte)0xf5, 0x46, (byte)0xe9, 0x6c, (byte)0xe5, (byte)0xdc, 0x1b,
|
||||||
0x2d, 0x00, 0x00, 0x00, 0x38, 0x0c, 0x14, 0x5f,
|
0x2d, 0x00, 0x00, 0x00, 0x38, 0x0c, 0x14, 0x5f,
|
||||||
0x08, 0x07, 0x30, 0x04, 0x29, 0x0d, 0x14, 0x5f,
|
0x08, 0x07, 0x30, 0x04, 0x29, 0x0d, 0x14, 0x5f,
|
||||||
@ -24,15 +26,15 @@ public class MasterHeaderBlockTest extends TestCase {
|
|||||||
// Using byte values since it should be a bit more clear where they came from
|
// Using byte values since it should be a bit more clear where they came from
|
||||||
assertEquals(0x1bdc, b.getMasterCrc());
|
assertEquals(0x1bdc, b.getMasterCrc());
|
||||||
assertEquals(0x2d, b.getTotalRecords());
|
assertEquals(0x2d, b.getTotalRecords());
|
||||||
assertEquals(new ByteSource(new byte[] {0x38, 0x0c, 0x14, 0x5f, 0x08, 0x07, 0x30, 0x04}).readDate(), b.getArchiveCreateWhen());
|
assertEquals(new LittleEndianByteInputStream(new byte[] {0x38, 0x0c, 0x14, 0x5f, 0x08, 0x07, 0x30, 0x04}).readDate(), b.getArchiveCreateWhen());
|
||||||
assertEquals(new ByteSource(new byte[] {0x29, 0x0d, 0x14, 0x5f, 0x08, 0x07, 0x01, 0x04}).readDate(), b.getArchiveModWhen());
|
assertEquals(new LittleEndianByteInputStream(new byte[] {0x29, 0x0d, 0x14, 0x5f, 0x08, 0x07, 0x01, 0x04}).readDate(), b.getArchiveModWhen());
|
||||||
assertEquals(0x01, b.getMasterVersion());
|
assertEquals(0x01, b.getMasterVersion());
|
||||||
assertEquals(0x1acae, b.getMasterEof());
|
assertEquals(0x1acae, b.getMasterEof());
|
||||||
assertTrue(b.isValidCrc());
|
assertTrue(b.isValidCrc());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithInvalidCrc() throws IOException {
|
public void testWithInvalidCrc() throws IOException {
|
||||||
ByteSource bs = new ByteSource(new byte[] {
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream(new byte[] {
|
||||||
0x4e, (byte)0xf5, 0x46, (byte)0xe9, 0x6c, (byte)0xe5, 0x00, 0x00, // <-- Bad CRC!
|
0x4e, (byte)0xf5, 0x46, (byte)0xe9, 0x6c, (byte)0xe5, 0x00, 0x00, // <-- Bad CRC!
|
||||||
0x2d, 0x00, 0x00, 0x00, 0x38, 0x0c, 0x14, 0x5f,
|
0x2d, 0x00, 0x00, 0x00, 0x38, 0x0c, 0x14, 0x5f,
|
||||||
0x08, 0x07, 0x30, 0x04, 0x29, 0x0d, 0x14, 0x5f,
|
0x08, 0x07, 0x30, 0x04, 0x29, 0x0d, 0x14, 0x5f,
|
||||||
|
@ -2,6 +2,8 @@ package com.webcodepro.shrinkit;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import com.webcodepro.shrinkit.io.LittleEndianByteInputStream;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -19,7 +21,7 @@ public class ThreadRecordTest extends TestCase {
|
|||||||
0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x20, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00
|
0x00, 0x20, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00
|
||||||
};
|
};
|
||||||
ByteSource bs = new ByteSource(data);
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream(data);
|
||||||
ThreadRecord r = new ThreadRecord(bs);
|
ThreadRecord r = new ThreadRecord(bs);
|
||||||
assertEquals(ThreadClass.DATA, r.getThreadClass());
|
assertEquals(ThreadClass.DATA, r.getThreadClass());
|
||||||
assertEquals(ThreadFormat.DYNAMIC_LZW1, r.getThreadFormat());
|
assertEquals(ThreadFormat.DYNAMIC_LZW1, r.getThreadFormat());
|
||||||
@ -39,7 +41,7 @@ public class ThreadRecordTest extends TestCase {
|
|||||||
0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
|
0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x10, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00
|
0x00, 0x10, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00
|
||||||
};
|
};
|
||||||
ByteSource bs = new ByteSource(data);
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream(data);
|
||||||
ThreadRecord r1 = new ThreadRecord(bs);
|
ThreadRecord r1 = new ThreadRecord(bs);
|
||||||
assertEquals(ThreadClass.DATA, r1.getThreadClass());
|
assertEquals(ThreadClass.DATA, r1.getThreadClass());
|
||||||
assertEquals(ThreadFormat.DYNAMIC_LZW1, r1.getThreadFormat());
|
assertEquals(ThreadFormat.DYNAMIC_LZW1, r1.getThreadFormat());
|
||||||
@ -64,7 +66,7 @@ public class ThreadRecordTest extends TestCase {
|
|||||||
0x02, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00,
|
0x02, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x51, 0x45, 0x07, 0x00
|
0x00, 0x00, 0x00, 0x00, 0x51, 0x45, 0x07, 0x00
|
||||||
};
|
};
|
||||||
ByteSource bs = new ByteSource(data);
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream(data);
|
||||||
ThreadRecord r = new ThreadRecord(bs);
|
ThreadRecord r = new ThreadRecord(bs);
|
||||||
assertEquals(ThreadClass.DATA, r.getThreadClass());
|
assertEquals(ThreadClass.DATA, r.getThreadClass());
|
||||||
assertEquals(ThreadFormat.DYNAMIC_LZW1, r.getThreadFormat());
|
assertEquals(ThreadFormat.DYNAMIC_LZW1, r.getThreadFormat());
|
||||||
@ -86,7 +88,7 @@ public class ThreadRecordTest extends TestCase {
|
|||||||
0x02, 0x00, 0x03, 0x00, 0x00, 0x00, 0x58, 0x4a,
|
0x02, 0x00, 0x03, 0x00, 0x00, 0x00, 0x58, 0x4a,
|
||||||
(byte)0xd6, 0x06, 0x00, 0x00, (byte)0xd4, 0x03, 0x00, 0x00
|
(byte)0xd6, 0x06, 0x00, 0x00, (byte)0xd4, 0x03, 0x00, 0x00
|
||||||
};
|
};
|
||||||
ByteSource bs = new ByteSource(data);
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream(data);
|
||||||
ThreadRecord r1 = new ThreadRecord(bs);
|
ThreadRecord r1 = new ThreadRecord(bs);
|
||||||
assertEquals(ThreadClass.FILENAME, r1.getThreadClass());
|
assertEquals(ThreadClass.FILENAME, r1.getThreadClass());
|
||||||
assertEquals(ThreadFormat.UNCOMPRESSED, r1.getThreadFormat());
|
assertEquals(ThreadFormat.UNCOMPRESSED, r1.getThreadFormat());
|
||||||
@ -122,7 +124,7 @@ public class ThreadRecordTest extends TestCase {
|
|||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||||
};
|
};
|
||||||
ByteSource bs = new ByteSource(data);
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream(data);
|
||||||
ThreadRecord r = new ThreadRecord(bs);
|
ThreadRecord r = new ThreadRecord(bs);
|
||||||
r.readThreadData(bs);
|
r.readThreadData(bs);
|
||||||
assertTrue(r.isText());
|
assertTrue(r.isText());
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
package com.webcodepro.shrinkit;
|
package com.webcodepro.shrinkit.io;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
import com.webcodepro.shrinkit.ByteSource;
|
import com.webcodepro.shrinkit.io.LittleEndianByteInputStream;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exercise the ByteSource class.
|
* Exercise the LittleEndianByteInputStream class.
|
||||||
* @author robgreene@users.sourceforge.net
|
* @author robgreene@users.sourceforge.net
|
||||||
*/
|
*/
|
||||||
public class ByteSourceTest extends TestCase {
|
public class LittleEndianByteInputStreamTest extends TestCase {
|
||||||
public void testReadA() throws IOException {
|
public void testReadA() throws IOException {
|
||||||
ByteSource bs = new ByteSource("a".getBytes());
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream("a".getBytes());
|
||||||
assertEquals('a', bs.read());
|
assertEquals('a', bs.read());
|
||||||
assertEquals(-1, bs.read());
|
assertEquals(-1, bs.read());
|
||||||
assertEquals(1, bs.getTotalBytesRead());
|
assertEquals(1, bs.getTotalBytesRead());
|
||||||
}
|
}
|
||||||
public void testReadB() throws IOException {
|
public void testReadB() throws IOException {
|
||||||
// Just to ensure we can get more than one byte...
|
// Just to ensure we can get more than one byte...
|
||||||
ByteSource bs = new ByteSource("hello".getBytes());
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream("hello".getBytes());
|
||||||
assertEquals('h', bs.read());
|
assertEquals('h', bs.read());
|
||||||
assertEquals('e', bs.read());
|
assertEquals('e', bs.read());
|
||||||
assertEquals('l', bs.read());
|
assertEquals('l', bs.read());
|
||||||
@ -32,7 +32,7 @@ public class ByteSourceTest extends TestCase {
|
|||||||
}
|
}
|
||||||
public void testReadBytesInt() throws IOException {
|
public void testReadBytesInt() throws IOException {
|
||||||
// Ensure we read the requested data.
|
// Ensure we read the requested data.
|
||||||
ByteSource bs = new ByteSource("HelloWorld".getBytes());
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream("HelloWorld".getBytes());
|
||||||
assertEquals("Hello", new String(bs.readBytes(5)));
|
assertEquals("Hello", new String(bs.readBytes(5)));
|
||||||
assertEquals("World", new String(bs.readBytes(5)));
|
assertEquals("World", new String(bs.readBytes(5)));
|
||||||
assertEquals(-1, bs.read());
|
assertEquals(-1, bs.read());
|
||||||
@ -40,7 +40,7 @@ public class ByteSourceTest extends TestCase {
|
|||||||
}
|
}
|
||||||
public void textReadBytesIntError() {
|
public void textReadBytesIntError() {
|
||||||
// Ensure that we fail appropriately
|
// Ensure that we fail appropriately
|
||||||
ByteSource bs = new ByteSource("Hi".getBytes());
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream("Hi".getBytes());
|
||||||
try {
|
try {
|
||||||
bs.readBytes(3);
|
bs.readBytes(3);
|
||||||
fail();
|
fail();
|
||||||
@ -50,42 +50,42 @@ public class ByteSourceTest extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void testCheckNuFileId() throws IOException {
|
public void testCheckNuFileId() throws IOException {
|
||||||
ByteSource bs = new ByteSource(new byte[] { 0x4e, (byte)0xf5, 0x46, (byte)0xe9, 0x6c, (byte)0xe5 });
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream(new byte[] { 0x4e, (byte)0xf5, 0x46, (byte)0xe9, 0x6c, (byte)0xe5 });
|
||||||
assertTrue(bs.checkNuFileId());
|
assertTrue(bs.checkNuFileId());
|
||||||
assertEquals(6, bs.getTotalBytesRead());
|
assertEquals(6, bs.getTotalBytesRead());
|
||||||
bs = new ByteSource("NotNuFile".getBytes());
|
bs = new LittleEndianByteInputStream("NotNuFile".getBytes());
|
||||||
assertFalse(bs.checkNuFileId());
|
assertFalse(bs.checkNuFileId());
|
||||||
}
|
}
|
||||||
public void testCheckNuFxId() throws IOException {
|
public void testCheckNuFxId() throws IOException {
|
||||||
ByteSource bs = new ByteSource(new byte[] { 0x4e, (byte)0xf5, 0x46, (byte)0xd8 });
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream(new byte[] { 0x4e, (byte)0xf5, 0x46, (byte)0xd8 });
|
||||||
assertTrue(bs.checkNuFxId());
|
assertTrue(bs.checkNuFxId());
|
||||||
assertEquals(4, bs.getTotalBytesRead());
|
assertEquals(4, bs.getTotalBytesRead());
|
||||||
bs = new ByteSource("NotNuFx".getBytes());
|
bs = new LittleEndianByteInputStream("NotNuFx".getBytes());
|
||||||
assertFalse(bs.checkNuFxId());
|
assertFalse(bs.checkNuFxId());
|
||||||
}
|
}
|
||||||
public void testReadWord() throws IOException {
|
public void testReadWord() throws IOException {
|
||||||
ByteSource bs = new ByteSource(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 });
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 });
|
||||||
assertEquals(0x0201, bs.readWord());
|
assertEquals(0x0201, bs.readWord());
|
||||||
assertEquals(0x0403, bs.readWord());
|
assertEquals(0x0403, bs.readWord());
|
||||||
assertEquals(4, bs.getTotalBytesRead());
|
assertEquals(4, bs.getTotalBytesRead());
|
||||||
}
|
}
|
||||||
public void testReadWordHighBitSet() throws IOException {
|
public void testReadWordHighBitSet() throws IOException {
|
||||||
ByteSource bs = new ByteSource(new byte[] { (byte)0xff, (byte)0xff });
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream(new byte[] { (byte)0xff, (byte)0xff });
|
||||||
assertEquals(0xffff, bs.readWord());
|
assertEquals(0xffff, bs.readWord());
|
||||||
assertEquals(2, bs.getTotalBytesRead());
|
assertEquals(2, bs.getTotalBytesRead());
|
||||||
}
|
}
|
||||||
public void testReadLong() throws IOException {
|
public void testReadLong() throws IOException {
|
||||||
ByteSource bs = new ByteSource(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 });
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 });
|
||||||
assertEquals(0x04030201, bs.readLong());
|
assertEquals(0x04030201, bs.readLong());
|
||||||
assertEquals(4, bs.getTotalBytesRead());
|
assertEquals(4, bs.getTotalBytesRead());
|
||||||
}
|
}
|
||||||
public void testReadLongHighBitSet() throws IOException {
|
public void testReadLongHighBitSet() throws IOException {
|
||||||
ByteSource bs = new ByteSource(new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff });
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream(new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff });
|
||||||
assertEquals(0xffffffffL, bs.readLong());
|
assertEquals(0xffffffffL, bs.readLong());
|
||||||
assertEquals(4, bs.getTotalBytesRead());
|
assertEquals(4, bs.getTotalBytesRead());
|
||||||
}
|
}
|
||||||
public void testReadDate() throws IOException {
|
public void testReadDate() throws IOException {
|
||||||
ByteSource bs = new ByteSource(new byte[] {
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream(new byte[] {
|
||||||
// From NuFX documentation, final revision 3
|
// From NuFX documentation, final revision 3
|
||||||
0x00, 0x0a, 0x01, 0x58, 0x16, 0x0a, 0x00, 0x07, // 01:10:00am 10/22/1988 saturday
|
0x00, 0x0a, 0x01, 0x58, 0x16, 0x0a, 0x00, 0x07, // 01:10:00am 10/22/1988 saturday
|
||||||
0x00, 0x10, 0x0b, 0x58, 0x11, 0x0b, 0x00, 0x05, // 11:16:00am 11/17/1988 thursday
|
0x00, 0x10, 0x0b, 0x58, 0x11, 0x0b, 0x00, 0x05, // 11:16:00am 11/17/1988 thursday
|
||||||
@ -97,7 +97,7 @@ public class ByteSourceTest extends TestCase {
|
|||||||
assertEquals(24, bs.getTotalBytesRead());
|
assertEquals(24, bs.getTotalBytesRead());
|
||||||
}
|
}
|
||||||
public void testReadNullDate() throws IOException {
|
public void testReadNullDate() throws IOException {
|
||||||
ByteSource bs = new ByteSource(new byte[] {
|
LittleEndianByteInputStream bs = new LittleEndianByteInputStream(new byte[] {
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // null date
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // null date
|
||||||
});
|
});
|
||||||
assertNull(bs.readDate());
|
assertNull(bs.readDate());
|
@ -5,7 +5,6 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import com.webcodepro.shrinkit.ByteSource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exercise the LZW encoder and decoders.
|
* Exercise the LZW encoder and decoders.
|
||||||
@ -27,7 +26,7 @@ public class LzwTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testLzwDecoder2() throws IOException {
|
public void testLzwDecoder2() throws IOException {
|
||||||
RleInputStream is = new RleInputStream(new ByteSource(new LzwInputStream(new BitInputStream(new ByteArrayInputStream(getHgrColorsLzw1()), 9))));
|
RleInputStream is = new RleInputStream(new LittleEndianByteInputStream(new LzwInputStream(new BitInputStream(new ByteArrayInputStream(getHgrColorsLzw1()), 9))));
|
||||||
|
|
||||||
int bytes = 0;
|
int bytes = 0;
|
||||||
int b;
|
int b;
|
||||||
|
@ -7,7 +7,6 @@ import java.io.OutputStream;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import com.webcodepro.shrinkit.ByteSource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exercise the RLE encoder and decoders.
|
* Exercise the RLE encoder and decoders.
|
||||||
@ -16,7 +15,7 @@ import com.webcodepro.shrinkit.ByteSource;
|
|||||||
*/
|
*/
|
||||||
public class RleTest extends TestCase {
|
public class RleTest extends TestCase {
|
||||||
public void testInputStream() throws IOException {
|
public void testInputStream() throws IOException {
|
||||||
InputStream is = new RleInputStream(new ByteSource(getPatternFileRle()));
|
InputStream is = new RleInputStream(new LittleEndianByteInputStream(getPatternFileRle()));
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
copy(is,os);
|
copy(is,os);
|
||||||
byte[] expected = getPatternFileUncompressed();
|
byte[] expected = getPatternFileUncompressed();
|
||||||
|
Loading…
Reference in New Issue
Block a user