mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-06-08 04:29:35 +00:00
removed ThreadHeader
This commit is contained in:
parent
5681aa4270
commit
838791ad05
|
@ -15,7 +15,7 @@ class LZW
|
|||
protected byte runLengthChar;
|
||||
protected int crc;
|
||||
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 bitsLeft; // unused bits left in buffer
|
||||
|
|
|
@ -4,70 +4,127 @@ package com.bytezone.diskbrowser.utilities;
|
|||
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 String fileName;
|
||||
private String message;
|
||||
private LZW lzw;
|
||||
|
||||
private boolean hasDisk;
|
||||
private boolean hasFile;
|
||||
private boolean hasFileName;
|
||||
|
||||
private int fileSize;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
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);
|
||||
|
||||
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:
|
||||
if (header.threadKind == 1)
|
||||
message = new String (data, 0, header.uncompressedEOF);
|
||||
switch (threadKind)
|
||||
{
|
||||
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;
|
||||
|
||||
case 1:
|
||||
switch (threadKind)
|
||||
{
|
||||
case 0: // create directory
|
||||
break;
|
||||
case 1: // undefined
|
||||
case 2: // undefined
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
lzw = switch (header.threadFormat)
|
||||
switch (threadKind)
|
||||
{
|
||||
case 2 -> new LZW1 (data);
|
||||
case 3 ->
|
||||
{
|
||||
int length = header.threadKind == 1 ? 0 : header.uncompressedEOF;
|
||||
yield new LZW2 (data, header.threadCrc, length);
|
||||
}
|
||||
default -> null; // 1 = Huffman Squeeze
|
||||
};
|
||||
|
||||
if (header.threadKind == 0) // file
|
||||
{
|
||||
hasFile = true;
|
||||
if (lzw != null)
|
||||
fileSize = lzw.getSize ();
|
||||
else
|
||||
fileSize = header.uncompressedEOF;
|
||||
case 0: // data fork of file
|
||||
hasFile = true;
|
||||
fileSize = lzw != null ? lzw.getSize () : uncompressedEOF;
|
||||
break;
|
||||
case 1: // disk image
|
||||
hasDisk = true;
|
||||
break;
|
||||
case 2: // resource fork of file
|
||||
break;
|
||||
}
|
||||
else if (header.threadKind == 1) // disk image
|
||||
hasDisk = true;
|
||||
|
||||
break;
|
||||
|
||||
case 3:
|
||||
if (header.threadKind == 0)
|
||||
switch (threadKind)
|
||||
{
|
||||
hasFileName = true;
|
||||
fileName = new String (data, 0, header.uncompressedEOF);
|
||||
case 0: // filename
|
||||
hasFileName = true;
|
||||
fileName = new String (data, 0, uncompressedEOF);
|
||||
break;
|
||||
|
||||
case 1: // undefined
|
||||
case 2: // undefined
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
System.out.println ("Unknown threadClass: " + header.threadClass);
|
||||
System.out.println ("Unknown threadClass: " + threadClass);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,15 +132,14 @@ class Thread
|
|||
boolean hasFile (String fileName)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return header.threadClass == 3 && this.fileName != null
|
||||
&& this.fileName.equals (fileName);
|
||||
return threadClass == 3 && this.fileName != null && this.fileName.equals (fileName);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public byte[] getData ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (header.threadFormat == 0) // uncompressed
|
||||
if (threadFormat == 0) // uncompressed
|
||||
return data;
|
||||
|
||||
return lzw.getData ();
|
||||
|
@ -93,14 +149,14 @@ class Thread
|
|||
int getCompressedEOF ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return header.compressedEOF;
|
||||
return compressedEOF;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
int getUncompressedEOF ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return header.uncompressedEOF;
|
||||
return uncompressedEOF;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
|
@ -143,7 +199,17 @@ class Thread
|
|||
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)
|
||||
text.append ("\n filename .......... " + fileName);
|
||||
|
|
|
@ -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 ();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user