From 1b86b31233f929e1c9c0577bd46fcd75b27bf2e3 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Wed, 11 May 2022 10:09:27 +1000 Subject: [PATCH] removed GregorianCalendar --- .../diskbrowser/pascal/CatalogEntry.java | 2 ++ .../diskbrowser/pascal/FileEntry.java | 2 +- .../pascal/PascalCatalogSector.java | 17 ++++++++------- .../diskbrowser/pascal/PascalDisk.java | 21 ++++++++++++++----- .../diskbrowser/pascal/VolumeEntry.java | 4 ++-- .../diskbrowser/utilities/Utility.java | 7 +++---- 6 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/com/bytezone/diskbrowser/pascal/CatalogEntry.java b/src/com/bytezone/diskbrowser/pascal/CatalogEntry.java index c908226..9847f5a 100644 --- a/src/com/bytezone/diskbrowser/pascal/CatalogEntry.java +++ b/src/com/bytezone/diskbrowser/pascal/CatalogEntry.java @@ -1,5 +1,6 @@ package com.bytezone.diskbrowser.pascal; +import java.time.LocalDate; import java.util.ArrayList; import java.util.GregorianCalendar; import java.util.List; @@ -23,6 +24,7 @@ abstract class CatalogEntry implements AppleFileSource protected int lastBlock; // block AFTER last used block protected int fileType; protected GregorianCalendar date; + protected LocalDate localDate; protected int bytesUsedInLastBlock; protected final List blocks = new ArrayList<> (); diff --git a/src/com/bytezone/diskbrowser/pascal/FileEntry.java b/src/com/bytezone/diskbrowser/pascal/FileEntry.java index aad1bfd..5bd9680 100644 --- a/src/com/bytezone/diskbrowser/pascal/FileEntry.java +++ b/src/com/bytezone/diskbrowser/pascal/FileEntry.java @@ -26,7 +26,7 @@ public class FileEntry extends CatalogEntry super (parent, buffer); bytesUsedInLastBlock = Utility.getShort (buffer, 22); - date = Utility.getPascalDate (buffer, 24); + localDate = Utility.getPascalLocalDate (buffer, 24); int max = Math.min (lastBlock, parent.getDisk ().getTotalBlocks ()); for (int i = firstBlock; i < max; i++) diff --git a/src/com/bytezone/diskbrowser/pascal/PascalCatalogSector.java b/src/com/bytezone/diskbrowser/pascal/PascalCatalogSector.java index 8700ee4..0d80f7b 100644 --- a/src/com/bytezone/diskbrowser/pascal/PascalCatalogSector.java +++ b/src/com/bytezone/diskbrowser/pascal/PascalCatalogSector.java @@ -1,7 +1,8 @@ package com.bytezone.diskbrowser.pascal; -import java.text.DateFormat; -import java.util.GregorianCalendar; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; import java.util.List; import com.bytezone.diskbrowser.disk.AbstractSector; @@ -14,7 +15,8 @@ import com.bytezone.diskbrowser.utilities.Utility; class PascalCatalogSector extends AbstractSector // -----------------------------------------------------------------------------------// { - private final DateFormat df = DateFormat.getDateInstance (DateFormat.SHORT); + // private final DateFormat df = DateFormat.getDateInstance (DateFormat.SHORT); + private final DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDate (FormatStyle.SHORT); private static String[] fileTypes = { "Volume", "Bad", "Code", "Text", "Info", "Data", "Graf", "Foto", "SecureDir" }; @@ -44,8 +46,9 @@ class PascalCatalogSector extends AbstractSector addTextAndDecimal (text, buffer, 16, 2, "Files on disk"); addTextAndDecimal (text, buffer, 18, 2, "First block of volume"); - GregorianCalendar calendar = Utility.getPascalDate (buffer, 20); - String date = calendar == null ? "--" : df.format (calendar.getTime ()); + LocalDate localDate = Utility.getPascalLocalDate (buffer, 20); + String date = localDate == null ? "--" : localDate.format (dtf); + addText (text, buffer, 20, 2, "Most recent date setting : " + date); addTextAndDecimal (text, buffer, 22, 4, "Reserved"); @@ -71,8 +74,8 @@ class PascalCatalogSector extends AbstractSector addText (text, buffer, ptr + 18, 4, "File name : " + name); addTextAndDecimal (text, buffer, ptr + 22, 2, "Bytes in file's last block"); - calendar = Utility.getPascalDate (buffer, ptr + 24); - date = calendar == null ? "--" : df.format (calendar.getTime ()); + localDate = Utility.getPascalLocalDate (buffer, ptr + 24); + date = localDate == null ? "--" : localDate.format (dtf); addText (text, buffer, ptr + 24, 2, "Date : " + date); ptr += PascalDisk.CATALOG_ENTRY_SIZE; diff --git a/src/com/bytezone/diskbrowser/pascal/PascalDisk.java b/src/com/bytezone/diskbrowser/pascal/PascalDisk.java index 6fa34e7..1e3a131 100755 --- a/src/com/bytezone/diskbrowser/pascal/PascalDisk.java +++ b/src/com/bytezone/diskbrowser/pascal/PascalDisk.java @@ -2,8 +2,10 @@ package com.bytezone.diskbrowser.pascal; import java.awt.Color; import java.text.DateFormat; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; import java.util.ArrayList; -import java.util.GregorianCalendar; import java.util.List; import javax.swing.tree.DefaultMutableTreeNode; @@ -29,6 +31,7 @@ public class PascalDisk extends AbstractFormattedDisk { static final int CATALOG_ENTRY_SIZE = 26; private final DateFormat df = DateFormat.getDateInstance (DateFormat.SHORT); + private final DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDate (FormatStyle.SHORT); private final VolumeEntry volumeEntry; private final PascalCatalogSector diskCatalogSector; @@ -232,8 +235,10 @@ public class PascalDisk extends AbstractFormattedDisk } int lastByte = Utility.getShort (buffer, ptr + 22); - GregorianCalendar date = Utility.getPascalDate (buffer, 24); - String dateString = date == null ? "" : date.toString (); + // GregorianCalendar date = Utility.getPascalDate (buffer, 24); + LocalDate localDate = Utility.getPascalLocalDate (buffer, 24); + String dateString = localDate == null ? "" + : localDate.format (DateTimeFormatter.ofLocalizedDate (FormatStyle.SHORT)); if (debug) System.out.printf ("%4d %4d %d %-15s %d %s%n", firstBlock, lastBlock, kind, new String (buffer, ptr + 7, nameLength), lastByte, dateString); @@ -297,7 +302,9 @@ public class PascalDisk extends AbstractFormattedDisk String newLine2 = newLine + newLine; String line = "---- --------------- ---- -------- ------- ---- ---- ----" + newLine; - String date = volumeEntry.date == null ? "--" : df.format (volumeEntry.date.getTime ()); + + String date = volumeEntry.localDate == null ? "--" : volumeEntry.localDate.format (dtf); + StringBuilder text = new StringBuilder (); text.append ("File : " + getDisplayPath () + newLine2); text.append ("Volume : " + volumeEntry.name + newLine); @@ -311,16 +318,20 @@ public class PascalDisk extends AbstractFormattedDisk FileEntry ce = (FileEntry) fe; int size = ce.lastBlock - ce.firstBlock; usedBlocks += size; - date = ce.date == null ? "--" : df.format (ce.date.getTime ()); + + date = ce.localDate == null ? "--" : ce.localDate.format (dtf); + int bytes = (size - 1) * 512 + ce.bytesUsedInLastBlock; String fileType = ce.fileType < 0 || ce.fileType >= fileTypes.length ? "????" : fileTypes[ce.fileType]; text.append (String.format ("%4d %-15s %-6s %8s %,8d $%03X $%03X $%03X%n", size, ce.name, fileType, date, bytes, ce.firstBlock, ce.lastBlock, size)); } + text.append (line); text.append (String.format ("Blocks free : %3d Blocks used : %3d Total blocks : %3d%n", (volumeEntry.totalBlocks - usedBlocks), usedBlocks, volumeEntry.totalBlocks)); + return new DefaultAppleFileSource (volumeEntry.name, text.toString (), this); } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/pascal/VolumeEntry.java b/src/com/bytezone/diskbrowser/pascal/VolumeEntry.java index 25d18d9..78d5bc0 100644 --- a/src/com/bytezone/diskbrowser/pascal/VolumeEntry.java +++ b/src/com/bytezone/diskbrowser/pascal/VolumeEntry.java @@ -17,9 +17,9 @@ class VolumeEntry extends CatalogEntry { super (parent, buffer); - totalBlocks = Utility.getShort (buffer, 14); // 280 + totalBlocks = Utility.getShort (buffer, 14); // 280 totalFiles = Utility.getShort (buffer, 16); - date = Utility.getPascalDate (buffer, 20); // 2 bytes + localDate = Utility.getPascalLocalDate (buffer, 20); // 2 bytes } // ---------------------------------------------------------------------------------// diff --git a/src/com/bytezone/diskbrowser/utilities/Utility.java b/src/com/bytezone/diskbrowser/utilities/Utility.java index 73dde64..2a34415 100644 --- a/src/com/bytezone/diskbrowser/utilities/Utility.java +++ b/src/com/bytezone/diskbrowser/utilities/Utility.java @@ -9,9 +9,9 @@ import java.io.IOException; import java.math.BigDecimal; import java.math.MathContext; import java.time.DateTimeException; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Arrays; -import java.util.GregorianCalendar; import java.util.List; import java.util.zip.CRC32; import java.util.zip.Checksum; @@ -230,7 +230,6 @@ public final class Utility public static LocalDateTime getAppleDate (byte[] buffer, int offset) // ---------------------------------------------------------------------------------// { - // int yymmdd = readShort (buffer, offset); int yymmdd = getShort (buffer, offset); if (yymmdd != 0) { @@ -429,7 +428,7 @@ public final class Utility } // ---------------------------------------------------------------------------------// - public static GregorianCalendar getPascalDate (byte[] buffer, int offset) + public static LocalDate getPascalLocalDate (byte[] buffer, int offset) // ---------------------------------------------------------------------------------// { int date = Utility.getShort (buffer, offset); @@ -446,7 +445,7 @@ public final class Utility else year += 1900; - return new GregorianCalendar (year, month - 1, day); + return LocalDate.of (year, month, day); } // ---------------------------------------------------------------------------------//