From 09965c02aaada41ee8c98a89c84dffba50774f9d Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Sat, 8 Feb 2020 09:26:38 +1000 Subject: [PATCH] method header lines --- .../bytezone/diskbrowser/utilities/LZW.java | 20 +++++++++++++++++++ .../bytezone/diskbrowser/utilities/LZW1.java | 12 +++++++++-- .../bytezone/diskbrowser/utilities/LZW2.java | 8 ++++++++ .../bytezone/diskbrowser/utilities/NuFX.java | 18 +++++++++++++++++ .../diskbrowser/utilities/NumberRenderer.java | 10 ++++++++++ .../diskbrowser/utilities/Thread.java | 14 +++++++++++++ 6 files changed, 80 insertions(+), 2 deletions(-) diff --git a/src/com/bytezone/diskbrowser/utilities/LZW.java b/src/com/bytezone/diskbrowser/utilities/LZW.java index f401a7a..d1df7d8 100644 --- a/src/com/bytezone/diskbrowser/utilities/LZW.java +++ b/src/com/bytezone/diskbrowser/utilities/LZW.java @@ -3,7 +3,9 @@ package com.bytezone.diskbrowser.utilities; import java.util.ArrayList; import java.util.List; +// -----------------------------------------------------------------------------------// class LZW +// -----------------------------------------------------------------------------------// { static protected final String[] st = new String[0x1000]; static protected final int TRACK_LENGTH = 0x1000; @@ -21,31 +23,41 @@ class LZW private int startPtr; protected byte[] bytes; + // ---------------------------------------------------------------------------------// static + // ---------------------------------------------------------------------------------// { for (int i = 0; i < 256; i++) st[i] = "" + (char) i; } + // ---------------------------------------------------------------------------------// public void setBuffer (byte[] buffer, int ptr) + // ---------------------------------------------------------------------------------// { bytes = buffer; startPtr = this.ptr = ptr; bitsLeft = 0; } + // ---------------------------------------------------------------------------------// public int bytesRead () + // ---------------------------------------------------------------------------------// { return ptr - startPtr; } + // ---------------------------------------------------------------------------------// private void fillBuffer () + // ---------------------------------------------------------------------------------// { buffer = bytes[ptr++] & 0xFF; bitsLeft = 8; } + // ---------------------------------------------------------------------------------// private boolean readBoolean () + // ---------------------------------------------------------------------------------// { if (bitsLeft == 0) fillBuffer (); @@ -55,7 +67,9 @@ class LZW return bit; } + // ---------------------------------------------------------------------------------// int readInt (int width) + // ---------------------------------------------------------------------------------// { if (width < 8 || width > 12) throw new RuntimeException ("Illegal value of r = " + width); @@ -68,7 +82,9 @@ class LZW return x; } + // ---------------------------------------------------------------------------------// byte[] undoRLE (byte[] inBuffer, int inPtr, int length) + // ---------------------------------------------------------------------------------// { byte[] outBuffer = new byte[TRACK_LENGTH]; int outPtr = 0; @@ -92,7 +108,9 @@ class LZW return outBuffer; } + // ---------------------------------------------------------------------------------// public byte[] getData () + // ---------------------------------------------------------------------------------// { byte[] buffer = new byte[chunks.size () * TRACK_LENGTH]; int trackNumber = 0; @@ -106,7 +124,9 @@ class LZW return buffer; } + // ---------------------------------------------------------------------------------// protected int width (int maximumValue) + // ---------------------------------------------------------------------------------// { return 32 - Integer.numberOfLeadingZeros (maximumValue); } diff --git a/src/com/bytezone/diskbrowser/utilities/LZW1.java b/src/com/bytezone/diskbrowser/utilities/LZW1.java index c8d1544..a8d4ae6 100644 --- a/src/com/bytezone/diskbrowser/utilities/LZW1.java +++ b/src/com/bytezone/diskbrowser/utilities/LZW1.java @@ -2,9 +2,13 @@ package com.bytezone.diskbrowser.utilities; import java.util.Objects; +// -----------------------------------------------------------------------------------// class LZW1 extends LZW +// -----------------------------------------------------------------------------------// { + // ---------------------------------------------------------------------------------// public LZW1 (byte[] buffer) + // ---------------------------------------------------------------------------------// { bytes = Objects.requireNonNull (buffer); @@ -49,11 +53,13 @@ class LZW1 extends LZW } } + // ---------------------------------------------------------------------------------// 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 nextEntry = 0x100; // always start with a fresh table + int nextEntry = 0x100; // always start with a fresh table String prev = ""; while (ptr < rleLength) @@ -72,8 +78,10 @@ class LZW1 extends LZW return lzwBuffer; } + // ---------------------------------------------------------------------------------// @Override public String toString () + // ---------------------------------------------------------------------------------// { StringBuilder text = new StringBuilder (); diff --git a/src/com/bytezone/diskbrowser/utilities/LZW2.java b/src/com/bytezone/diskbrowser/utilities/LZW2.java index a2de8b4..57b4a5b 100644 --- a/src/com/bytezone/diskbrowser/utilities/LZW2.java +++ b/src/com/bytezone/diskbrowser/utilities/LZW2.java @@ -2,13 +2,17 @@ package com.bytezone.diskbrowser.utilities; import java.util.Objects; +// -----------------------------------------------------------------------------------// class LZW2 extends LZW +// -----------------------------------------------------------------------------------// { private int nextEntry = 0x100; private String prev = ""; private int codeWord; + // ---------------------------------------------------------------------------------// public LZW2 (byte[] buffer, int crc) + // ---------------------------------------------------------------------------------// { bytes = Objects.requireNonNull (buffer); @@ -67,7 +71,9 @@ class LZW2 extends LZW } } + // ---------------------------------------------------------------------------------// protected byte[] undoLZW (int rleLength) + // ---------------------------------------------------------------------------------// { byte[] lzwBuffer = new byte[rleLength]; // must fill this array from buffer int ptr = 0; @@ -97,8 +103,10 @@ class LZW2 extends LZW return lzwBuffer; } + // ---------------------------------------------------------------------------------// @Override public String toString () + // ---------------------------------------------------------------------------------// { StringBuilder text = new StringBuilder (); diff --git a/src/com/bytezone/diskbrowser/utilities/NuFX.java b/src/com/bytezone/diskbrowser/utilities/NuFX.java index 7a51940..e786b4b 100644 --- a/src/com/bytezone/diskbrowser/utilities/NuFX.java +++ b/src/com/bytezone/diskbrowser/utilities/NuFX.java @@ -7,7 +7,9 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +// -----------------------------------------------------------------------------------// public class NuFX +// -----------------------------------------------------------------------------------// { private static String[] fileSystems = { "", "ProDOS/SOS", "DOS 3.3", "DOS 3.2", "Apple II Pascal", "Macintosh HFS", @@ -20,19 +22,25 @@ public class NuFX private final List records = new ArrayList<> (); private final List threads = new ArrayList<> (); + // ---------------------------------------------------------------------------------// public NuFX (Path path) throws FileFormatException, IOException + // ---------------------------------------------------------------------------------// { buffer = Files.readAllBytes (path); readBuffer (); } + // ---------------------------------------------------------------------------------// public NuFX (File file) throws FileFormatException, IOException + // ---------------------------------------------------------------------------------// { buffer = Files.readAllBytes (file.toPath ()); readBuffer (); } + // ---------------------------------------------------------------------------------// private void readBuffer () + // ---------------------------------------------------------------------------------// { header = new Header (buffer); @@ -67,7 +75,9 @@ public class NuFX } } + // ---------------------------------------------------------------------------------// public byte[] getBuffer () + // ---------------------------------------------------------------------------------// { for (Thread thread : threads) if (thread.hasDisk ()) @@ -75,8 +85,10 @@ public class NuFX return null; } + // ---------------------------------------------------------------------------------// @Override public String toString () + // ---------------------------------------------------------------------------------// { for (Thread thread : threads) if (thread.hasDisk ()) @@ -84,7 +96,9 @@ public class NuFX return "no disk"; } + // ---------------------------------------------------------------------------------// protected static int getCRC (final byte[] buffer, int base) + // ---------------------------------------------------------------------------------// { int crc = base; for (int j = 0; j < buffer.length; j++) @@ -100,7 +114,9 @@ public class NuFX return crc; } + // ---------------------------------------------------------------------------------// class Header + // ---------------------------------------------------------------------------------// { private final int totalRecords; private final int version; @@ -178,7 +194,9 @@ public class NuFX } } + // ---------------------------------------------------------------------------------// class Record + // ---------------------------------------------------------------------------------// { private final int totThreads; private final int crc; diff --git a/src/com/bytezone/diskbrowser/utilities/NumberRenderer.java b/src/com/bytezone/diskbrowser/utilities/NumberRenderer.java index 34367d6..a126834 100644 --- a/src/com/bytezone/diskbrowser/utilities/NumberRenderer.java +++ b/src/com/bytezone/diskbrowser/utilities/NumberRenderer.java @@ -4,25 +4,35 @@ import java.text.NumberFormat; import javax.swing.SwingConstants; +// -----------------------------------------------------------------------------------// public class NumberRenderer extends FormatRenderer +// -----------------------------------------------------------------------------------// { + // ---------------------------------------------------------------------------------// public NumberRenderer (NumberFormat formatter) + // ---------------------------------------------------------------------------------// { super (formatter); setHorizontalAlignment (SwingConstants.RIGHT); } + // ---------------------------------------------------------------------------------// public static NumberRenderer getCurrencyRenderer () + // ---------------------------------------------------------------------------------// { return new NumberRenderer (NumberFormat.getCurrencyInstance ()); } + // ---------------------------------------------------------------------------------// public static NumberRenderer getIntegerRenderer () + // ---------------------------------------------------------------------------------// { return new NumberRenderer (NumberFormat.getIntegerInstance ()); } + // ---------------------------------------------------------------------------------// public static NumberRenderer getPercentRenderer () + // ---------------------------------------------------------------------------------// { return new NumberRenderer (NumberFormat.getPercentInstance ()); } diff --git a/src/com/bytezone/diskbrowser/utilities/Thread.java b/src/com/bytezone/diskbrowser/utilities/Thread.java index 6f10fc5..43977d4 100644 --- a/src/com/bytezone/diskbrowser/utilities/Thread.java +++ b/src/com/bytezone/diskbrowser/utilities/Thread.java @@ -1,6 +1,8 @@ package com.bytezone.diskbrowser.utilities; +// -----------------------------------------------------------------------------------// class Thread +// -----------------------------------------------------------------------------------// { private static String[] threadClassText = { "Message", "Control", "Data", "Filename" }; private static String[] formatText = @@ -18,7 +20,9 @@ class Thread private String message; private LZW lzw; + // ---------------------------------------------------------------------------------// public Thread (byte[] buffer, int offset, int dataOffset) + // ---------------------------------------------------------------------------------// { header = new ThreadHeader (buffer, offset); @@ -60,23 +64,31 @@ class Thread } } + // ---------------------------------------------------------------------------------// public byte[] getData () + // ---------------------------------------------------------------------------------// { return hasDisk () ? lzw.getData () : null; } + // ---------------------------------------------------------------------------------// int getCompressedEOF () + // ---------------------------------------------------------------------------------// { return header.compressedEOF; } + // ---------------------------------------------------------------------------------// public boolean hasDisk () + // ---------------------------------------------------------------------------------// { return lzw != null; } + // ---------------------------------------------------------------------------------// @Override public String toString () + // ---------------------------------------------------------------------------------// { StringBuilder text = new StringBuilder (header.toString ()); @@ -93,7 +105,9 @@ class Thread return text.toString (); } + // ---------------------------------------------------------------------------------// class ThreadHeader + // ---------------------------------------------------------------------------------// { private final int threadClass; private final int format;