removed ThreadHeader

This commit is contained in:
Denis Molony 2021-04-18 17:34:35 +10:00
parent 5681aa4270
commit 838791ad05
3 changed files with 102 additions and 92 deletions

View File

@ -15,7 +15,7 @@ class LZW
protected byte runLengthChar; protected byte runLengthChar;
protected int crc; protected int crc;
protected int crcBase; protected int crcBase;
int v3eof; // LZW/2 calculates the crc sans padding int v3eof; // LZW/2 calculates the crc sans padding
private int buffer; // one character buffer private int buffer; // one character buffer
private int bitsLeft; // unused bits left in buffer private int bitsLeft; // unused bits left in buffer

View File

@ -4,70 +4,127 @@ package com.bytezone.diskbrowser.utilities;
class Thread class Thread
// -----------------------------------------------------------------------------------// // -----------------------------------------------------------------------------------//
{ {
private final ThreadHeader header; private static String[] threadClassText = { "Message", "Control", "Data", "Filename" };
private static String[] formatText =
{ "Uncompressed", "Huffman squeeze", "LZW/1", "LZW/2", "Unix 12-bit Compress",
"Unix 16-bit Compress" };
private static String[][] threadKindText =
{ { "ASCII text", "predefined EOF", "IIgs icon" },
{ "create directory", "undefined", "undefined" },
{ "data fork", "disk image", "resource fork" },
{ "filename", "undefined", "undefined" } };
final int threadClass;
final int threadFormat;
final int threadKind;
final int threadCrc;
final int uncompressedEOF;
final int compressedEOF;
private final byte[] data; private final byte[] data;
private String fileName; private String fileName;
private String message; private String message;
private LZW lzw; private LZW lzw;
private boolean hasDisk; private boolean hasDisk;
private boolean hasFile; private boolean hasFile;
private boolean hasFileName; private boolean hasFileName;
private int fileSize; private int fileSize;
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
public Thread (byte[] buffer, int offset, int dataOffset) public Thread (byte[] buffer, int offset, int dataOffset)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
header = new ThreadHeader (buffer, offset); threadClass = Utility.getWord (buffer, offset);
threadFormat = Utility.getWord (buffer, offset + 2);
threadKind = Utility.getWord (buffer, offset + 4);
data = new byte[header.compressedEOF]; threadCrc = Utility.getWord (buffer, offset + 6);
uncompressedEOF = Utility.getLong (buffer, offset + 8);
compressedEOF = Utility.getLong (buffer, offset + 12);
data = new byte[compressedEOF];
System.arraycopy (buffer, dataOffset, data, 0, data.length); System.arraycopy (buffer, dataOffset, data, 0, data.length);
switch (header.threadClass) switch (threadFormat)
{
case 0: // uncompressed
break;
case 1: // Huffman Squeeze
break;
case 2: // Dynamic LZW/1
lzw = new LZW1 (data);
break;
case 3: // Dynamic LZW/2
int crcLength = threadKind == 1 ? 0 : uncompressedEOF;
lzw = new LZW2 (data, threadCrc, crcLength);
break;
case 4: // Unix 12-bit compress
break;
case 5: // Unix 16-bit compress
break;
}
switch (threadClass)
{ {
case 0: case 0:
if (header.threadKind == 1) switch (threadKind)
message = new String (data, 0, header.uncompressedEOF); {
case 0: // ASCII text (obsolete)
break;
case 1: // comp/uncomp eof may change
message = new String (data, 0, uncompressedEOF);
break;
case 2: // Apple IIgs icon
break;
}
break; break;
case 1: case 1:
switch (threadKind)
{
case 0: // create directory
break;
case 1: // undefined
case 2: // undefined
break;
}
break; break;
case 2: case 2:
lzw = switch (header.threadFormat) switch (threadKind)
{ {
case 2 -> new LZW1 (data); case 0: // data fork of file
case 3 -> hasFile = true;
{ fileSize = lzw != null ? lzw.getSize () : uncompressedEOF;
int length = header.threadKind == 1 ? 0 : header.uncompressedEOF; break;
yield new LZW2 (data, header.threadCrc, length); case 1: // disk image
} hasDisk = true;
default -> null; // 1 = Huffman Squeeze break;
}; case 2: // resource fork of file
break;
if (header.threadKind == 0) // file
{
hasFile = true;
if (lzw != null)
fileSize = lzw.getSize ();
else
fileSize = header.uncompressedEOF;
} }
else if (header.threadKind == 1) // disk image
hasDisk = true;
break; break;
case 3: case 3:
if (header.threadKind == 0) switch (threadKind)
{ {
hasFileName = true; case 0: // filename
fileName = new String (data, 0, header.uncompressedEOF); hasFileName = true;
fileName = new String (data, 0, uncompressedEOF);
break;
case 1: // undefined
case 2: // undefined
break;
} }
break; break;
default: default:
System.out.println ("Unknown threadClass: " + header.threadClass); System.out.println ("Unknown threadClass: " + threadClass);
} }
} }
@ -75,15 +132,14 @@ class Thread
boolean hasFile (String fileName) boolean hasFile (String fileName)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
return header.threadClass == 3 && this.fileName != null return threadClass == 3 && this.fileName != null && this.fileName.equals (fileName);
&& this.fileName.equals (fileName);
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
public byte[] getData () public byte[] getData ()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
if (header.threadFormat == 0) // uncompressed if (threadFormat == 0) // uncompressed
return data; return data;
return lzw.getData (); return lzw.getData ();
@ -93,14 +149,14 @@ class Thread
int getCompressedEOF () int getCompressedEOF ()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
return header.compressedEOF; return compressedEOF;
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
int getUncompressedEOF () int getUncompressedEOF ()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
return header.uncompressedEOF; return uncompressedEOF;
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@ -143,7 +199,17 @@ class Thread
public String toString () public String toString ()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (header.toString ()); StringBuilder text = new StringBuilder ();
text.append (String.format (" threadClass ....... %d %s%n", threadClass,
threadClassText[threadClass]));
text.append (String.format (" format ............ %d %s%n", threadFormat,
formatText[threadFormat]));
text.append (String.format (" kind .............. %d %s%n", threadKind,
threadKindText[threadClass][threadKind]));
text.append (String.format (" crc ............... %,d (%<04X)%n", threadCrc));
text.append (String.format (" uncompressedEOF ... %,d (%<08X)%n", uncompressedEOF));
text.append (String.format (" compressedEOF ..... %,d (%<08X)", compressedEOF));
if (fileName != null) if (fileName != null)
text.append ("\n filename .......... " + fileName); text.append ("\n filename .......... " + fileName);

View File

@ -1,56 +0,0 @@
package com.bytezone.diskbrowser.utilities;
// -----------------------------------------------------------------------------------//
class ThreadHeader
// -----------------------------------------------------------------------------------//
{
private static String[] threadClassText = { "Message", "Control", "Data", "Filename" };
private static String[] formatText =
{ "Uncompressed", "Huffman squeeze", "LZW/1", "LZW/2", "Unix 12-bit Compress",
"Unix 16-bit Compress" };
private static String[][] threadKindText =
{ { "ASCII text", "predefined EOF", "IIgs icon" },
{ "create directory", "undefined", "undefined" },
{ "data fork", "disk image", "resource fork" },
{ "filename", "undefined", "undefined" } };
final int threadClass;
final int threadFormat;
final int threadKind;
final int threadCrc;
final int uncompressedEOF;
final int compressedEOF;
// ---------------------------------------------------------------------------------//
public ThreadHeader (byte[] buffer, int offset)
// ---------------------------------------------------------------------------------//
{
threadClass = Utility.getWord (buffer, offset);
threadFormat = Utility.getWord (buffer, offset + 2);
threadKind = Utility.getWord (buffer, offset + 4);
threadCrc = Utility.getWord (buffer, offset + 6);
uncompressedEOF = Utility.getLong (buffer, offset + 8);
compressedEOF = Utility.getLong (buffer, offset + 12);
}
// ---------------------------------------------------------------------------------//
@Override
public String toString ()
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ();
text.append (String.format (" threadClass ....... %d %s%n", threadClass,
threadClassText[threadClass]));
text.append (String.format (" format ............ %d %s%n", threadFormat,
formatText[threadFormat]));
text.append (String.format (" kind .............. %d %s%n", threadKind,
threadKindText[threadClass][threadKind]));
text.append (String.format (" crc ............... %,d (%<04X)%n", threadCrc));
text.append (String.format (" uncompressedEOF ... %,d (%<08X)%n", uncompressedEOF));
text.append (String.format (" compressedEOF ..... %,d (%<08X)", compressedEOF));
return text.toString ();
}
}