method header lines

This commit is contained in:
Denis Molony 2020-02-08 09:26:38 +10:00
parent 32de2aa69d
commit 09965c02aa
6 changed files with 80 additions and 2 deletions

View File

@ -3,7 +3,9 @@ package com.bytezone.diskbrowser.utilities;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
// -----------------------------------------------------------------------------------//
class LZW class LZW
// -----------------------------------------------------------------------------------//
{ {
static protected final String[] st = new String[0x1000]; static protected final String[] st = new String[0x1000];
static protected final int TRACK_LENGTH = 0x1000; static protected final int TRACK_LENGTH = 0x1000;
@ -21,31 +23,41 @@ class LZW
private int startPtr; private int startPtr;
protected byte[] bytes; protected byte[] bytes;
// ---------------------------------------------------------------------------------//
static static
// ---------------------------------------------------------------------------------//
{ {
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++)
st[i] = "" + (char) i; st[i] = "" + (char) i;
} }
// ---------------------------------------------------------------------------------//
public void setBuffer (byte[] buffer, int ptr) public void setBuffer (byte[] buffer, int ptr)
// ---------------------------------------------------------------------------------//
{ {
bytes = buffer; bytes = buffer;
startPtr = this.ptr = ptr; startPtr = this.ptr = ptr;
bitsLeft = 0; bitsLeft = 0;
} }
// ---------------------------------------------------------------------------------//
public int bytesRead () public int bytesRead ()
// ---------------------------------------------------------------------------------//
{ {
return ptr - startPtr; return ptr - startPtr;
} }
// ---------------------------------------------------------------------------------//
private void fillBuffer () private void fillBuffer ()
// ---------------------------------------------------------------------------------//
{ {
buffer = bytes[ptr++] & 0xFF; buffer = bytes[ptr++] & 0xFF;
bitsLeft = 8; bitsLeft = 8;
} }
// ---------------------------------------------------------------------------------//
private boolean readBoolean () private boolean readBoolean ()
// ---------------------------------------------------------------------------------//
{ {
if (bitsLeft == 0) if (bitsLeft == 0)
fillBuffer (); fillBuffer ();
@ -55,7 +67,9 @@ class LZW
return bit; return bit;
} }
// ---------------------------------------------------------------------------------//
int readInt (int width) int readInt (int width)
// ---------------------------------------------------------------------------------//
{ {
if (width < 8 || width > 12) if (width < 8 || width > 12)
throw new RuntimeException ("Illegal value of r = " + width); throw new RuntimeException ("Illegal value of r = " + width);
@ -68,7 +82,9 @@ class LZW
return x; return x;
} }
// ---------------------------------------------------------------------------------//
byte[] undoRLE (byte[] inBuffer, int inPtr, int length) byte[] undoRLE (byte[] inBuffer, int inPtr, int length)
// ---------------------------------------------------------------------------------//
{ {
byte[] outBuffer = new byte[TRACK_LENGTH]; byte[] outBuffer = new byte[TRACK_LENGTH];
int outPtr = 0; int outPtr = 0;
@ -92,7 +108,9 @@ class LZW
return outBuffer; return outBuffer;
} }
// ---------------------------------------------------------------------------------//
public byte[] getData () public byte[] getData ()
// ---------------------------------------------------------------------------------//
{ {
byte[] buffer = new byte[chunks.size () * TRACK_LENGTH]; byte[] buffer = new byte[chunks.size () * TRACK_LENGTH];
int trackNumber = 0; int trackNumber = 0;
@ -106,7 +124,9 @@ class LZW
return buffer; return buffer;
} }
// ---------------------------------------------------------------------------------//
protected int width (int maximumValue) protected int width (int maximumValue)
// ---------------------------------------------------------------------------------//
{ {
return 32 - Integer.numberOfLeadingZeros (maximumValue); return 32 - Integer.numberOfLeadingZeros (maximumValue);
} }

View File

@ -2,9 +2,13 @@ package com.bytezone.diskbrowser.utilities;
import java.util.Objects; import java.util.Objects;
// -----------------------------------------------------------------------------------//
class LZW1 extends LZW class LZW1 extends LZW
// -----------------------------------------------------------------------------------//
{ {
// ---------------------------------------------------------------------------------//
public LZW1 (byte[] buffer) public LZW1 (byte[] buffer)
// ---------------------------------------------------------------------------------//
{ {
bytes = Objects.requireNonNull (buffer); bytes = Objects.requireNonNull (buffer);
@ -49,11 +53,13 @@ class LZW1 extends LZW
} }
} }
// ---------------------------------------------------------------------------------//
protected byte[] undoLZW (int rleLength) protected byte[] undoLZW (int rleLength)
// ---------------------------------------------------------------------------------//
{ {
byte[] lzwBuffer = new byte[rleLength]; // must fill this array from input byte[] lzwBuffer = new byte[rleLength]; // must fill this array from input
int ptr = 0; int ptr = 0;
int nextEntry = 0x100; // always start with a fresh table int nextEntry = 0x100; // always start with a fresh table
String prev = ""; String prev = "";
while (ptr < rleLength) while (ptr < rleLength)
@ -72,8 +78,10 @@ class LZW1 extends LZW
return lzwBuffer; return lzwBuffer;
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String toString () public String toString ()
// ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();

View File

@ -2,13 +2,17 @@ package com.bytezone.diskbrowser.utilities;
import java.util.Objects; import java.util.Objects;
// -----------------------------------------------------------------------------------//
class LZW2 extends LZW class LZW2 extends LZW
// -----------------------------------------------------------------------------------//
{ {
private int nextEntry = 0x100; private int nextEntry = 0x100;
private String prev = ""; private String prev = "";
private int codeWord; private int codeWord;
// ---------------------------------------------------------------------------------//
public LZW2 (byte[] buffer, int crc) public LZW2 (byte[] buffer, int crc)
// ---------------------------------------------------------------------------------//
{ {
bytes = Objects.requireNonNull (buffer); bytes = Objects.requireNonNull (buffer);
@ -67,7 +71,9 @@ class LZW2 extends LZW
} }
} }
// ---------------------------------------------------------------------------------//
protected byte[] undoLZW (int rleLength) protected byte[] undoLZW (int rleLength)
// ---------------------------------------------------------------------------------//
{ {
byte[] lzwBuffer = new byte[rleLength]; // must fill this array from buffer byte[] lzwBuffer = new byte[rleLength]; // must fill this array from buffer
int ptr = 0; int ptr = 0;
@ -97,8 +103,10 @@ class LZW2 extends LZW
return lzwBuffer; return lzwBuffer;
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String toString () public String toString ()
// ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();

View File

@ -7,7 +7,9 @@ import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
// -----------------------------------------------------------------------------------//
public class NuFX public class NuFX
// -----------------------------------------------------------------------------------//
{ {
private static String[] fileSystems = private static String[] fileSystems =
{ "", "ProDOS/SOS", "DOS 3.3", "DOS 3.2", "Apple II Pascal", "Macintosh HFS", { "", "ProDOS/SOS", "DOS 3.3", "DOS 3.2", "Apple II Pascal", "Macintosh HFS",
@ -20,19 +22,25 @@ public class NuFX
private final List<Record> records = new ArrayList<> (); private final List<Record> records = new ArrayList<> ();
private final List<Thread> threads = new ArrayList<> (); private final List<Thread> threads = new ArrayList<> ();
// ---------------------------------------------------------------------------------//
public NuFX (Path path) throws FileFormatException, IOException public NuFX (Path path) throws FileFormatException, IOException
// ---------------------------------------------------------------------------------//
{ {
buffer = Files.readAllBytes (path); buffer = Files.readAllBytes (path);
readBuffer (); readBuffer ();
} }
// ---------------------------------------------------------------------------------//
public NuFX (File file) throws FileFormatException, IOException public NuFX (File file) throws FileFormatException, IOException
// ---------------------------------------------------------------------------------//
{ {
buffer = Files.readAllBytes (file.toPath ()); buffer = Files.readAllBytes (file.toPath ());
readBuffer (); readBuffer ();
} }
// ---------------------------------------------------------------------------------//
private void readBuffer () private void readBuffer ()
// ---------------------------------------------------------------------------------//
{ {
header = new Header (buffer); header = new Header (buffer);
@ -67,7 +75,9 @@ public class NuFX
} }
} }
// ---------------------------------------------------------------------------------//
public byte[] getBuffer () public byte[] getBuffer ()
// ---------------------------------------------------------------------------------//
{ {
for (Thread thread : threads) for (Thread thread : threads)
if (thread.hasDisk ()) if (thread.hasDisk ())
@ -75,8 +85,10 @@ public class NuFX
return null; return null;
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String toString () public String toString ()
// ---------------------------------------------------------------------------------//
{ {
for (Thread thread : threads) for (Thread thread : threads)
if (thread.hasDisk ()) if (thread.hasDisk ())
@ -84,7 +96,9 @@ public class NuFX
return "no disk"; return "no disk";
} }
// ---------------------------------------------------------------------------------//
protected static int getCRC (final byte[] buffer, int base) protected static int getCRC (final byte[] buffer, int base)
// ---------------------------------------------------------------------------------//
{ {
int crc = base; int crc = base;
for (int j = 0; j < buffer.length; j++) for (int j = 0; j < buffer.length; j++)
@ -100,7 +114,9 @@ public class NuFX
return crc; return crc;
} }
// ---------------------------------------------------------------------------------//
class Header class Header
// ---------------------------------------------------------------------------------//
{ {
private final int totalRecords; private final int totalRecords;
private final int version; private final int version;
@ -178,7 +194,9 @@ public class NuFX
} }
} }
// ---------------------------------------------------------------------------------//
class Record class Record
// ---------------------------------------------------------------------------------//
{ {
private final int totThreads; private final int totThreads;
private final int crc; private final int crc;

View File

@ -4,25 +4,35 @@ import java.text.NumberFormat;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
// -----------------------------------------------------------------------------------//
public class NumberRenderer extends FormatRenderer public class NumberRenderer extends FormatRenderer
// -----------------------------------------------------------------------------------//
{ {
// ---------------------------------------------------------------------------------//
public NumberRenderer (NumberFormat formatter) public NumberRenderer (NumberFormat formatter)
// ---------------------------------------------------------------------------------//
{ {
super (formatter); super (formatter);
setHorizontalAlignment (SwingConstants.RIGHT); setHorizontalAlignment (SwingConstants.RIGHT);
} }
// ---------------------------------------------------------------------------------//
public static NumberRenderer getCurrencyRenderer () public static NumberRenderer getCurrencyRenderer ()
// ---------------------------------------------------------------------------------//
{ {
return new NumberRenderer (NumberFormat.getCurrencyInstance ()); return new NumberRenderer (NumberFormat.getCurrencyInstance ());
} }
// ---------------------------------------------------------------------------------//
public static NumberRenderer getIntegerRenderer () public static NumberRenderer getIntegerRenderer ()
// ---------------------------------------------------------------------------------//
{ {
return new NumberRenderer (NumberFormat.getIntegerInstance ()); return new NumberRenderer (NumberFormat.getIntegerInstance ());
} }
// ---------------------------------------------------------------------------------//
public static NumberRenderer getPercentRenderer () public static NumberRenderer getPercentRenderer ()
// ---------------------------------------------------------------------------------//
{ {
return new NumberRenderer (NumberFormat.getPercentInstance ()); return new NumberRenderer (NumberFormat.getPercentInstance ());
} }

View File

@ -1,6 +1,8 @@
package com.bytezone.diskbrowser.utilities; package com.bytezone.diskbrowser.utilities;
// -----------------------------------------------------------------------------------//
class Thread class Thread
// -----------------------------------------------------------------------------------//
{ {
private static String[] threadClassText = { "Message", "Control", "Data", "Filename" }; private static String[] threadClassText = { "Message", "Control", "Data", "Filename" };
private static String[] formatText = private static String[] formatText =
@ -18,7 +20,9 @@ class Thread
private String message; private String message;
private LZW lzw; private LZW lzw;
// ---------------------------------------------------------------------------------//
public Thread (byte[] buffer, int offset, int dataOffset) public Thread (byte[] buffer, int offset, int dataOffset)
// ---------------------------------------------------------------------------------//
{ {
header = new ThreadHeader (buffer, offset); header = new ThreadHeader (buffer, offset);
@ -60,23 +64,31 @@ class Thread
} }
} }
// ---------------------------------------------------------------------------------//
public byte[] getData () public byte[] getData ()
// ---------------------------------------------------------------------------------//
{ {
return hasDisk () ? lzw.getData () : null; return hasDisk () ? lzw.getData () : null;
} }
// ---------------------------------------------------------------------------------//
int getCompressedEOF () int getCompressedEOF ()
// ---------------------------------------------------------------------------------//
{ {
return header.compressedEOF; return header.compressedEOF;
} }
// ---------------------------------------------------------------------------------//
public boolean hasDisk () public boolean hasDisk ()
// ---------------------------------------------------------------------------------//
{ {
return lzw != null; return lzw != null;
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String toString () public String toString ()
// ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (header.toString ()); StringBuilder text = new StringBuilder (header.toString ());
@ -93,7 +105,9 @@ class Thread
return text.toString (); return text.toString ();
} }
// ---------------------------------------------------------------------------------//
class ThreadHeader class ThreadHeader
// ---------------------------------------------------------------------------------//
{ {
private final int threadClass; private final int threadClass;
private final int format; private final int format;