removed GregorianCalendar

This commit is contained in:
Denis Molony 2022-05-11 10:09:27 +10:00
parent 1b9e9d47ac
commit 1b86b31233
6 changed files with 34 additions and 19 deletions

View File

@ -1,5 +1,6 @@
package com.bytezone.diskbrowser.pascal; package com.bytezone.diskbrowser.pascal;
import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.List; import java.util.List;
@ -23,6 +24,7 @@ abstract class CatalogEntry implements AppleFileSource
protected int lastBlock; // block AFTER last used block protected int lastBlock; // block AFTER last used block
protected int fileType; protected int fileType;
protected GregorianCalendar date; protected GregorianCalendar date;
protected LocalDate localDate;
protected int bytesUsedInLastBlock; protected int bytesUsedInLastBlock;
protected final List<DiskAddress> blocks = new ArrayList<> (); protected final List<DiskAddress> blocks = new ArrayList<> ();

View File

@ -26,7 +26,7 @@ public class FileEntry extends CatalogEntry
super (parent, buffer); super (parent, buffer);
bytesUsedInLastBlock = Utility.getShort (buffer, 22); bytesUsedInLastBlock = Utility.getShort (buffer, 22);
date = Utility.getPascalDate (buffer, 24); localDate = Utility.getPascalLocalDate (buffer, 24);
int max = Math.min (lastBlock, parent.getDisk ().getTotalBlocks ()); int max = Math.min (lastBlock, parent.getDisk ().getTotalBlocks ());
for (int i = firstBlock; i < max; i++) for (int i = firstBlock; i < max; i++)

View File

@ -1,7 +1,8 @@
package com.bytezone.diskbrowser.pascal; package com.bytezone.diskbrowser.pascal;
import java.text.DateFormat; import java.time.LocalDate;
import java.util.GregorianCalendar; import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.List; import java.util.List;
import com.bytezone.diskbrowser.disk.AbstractSector; import com.bytezone.diskbrowser.disk.AbstractSector;
@ -14,7 +15,8 @@ import com.bytezone.diskbrowser.utilities.Utility;
class PascalCatalogSector extends AbstractSector 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 = private static String[] fileTypes =
{ "Volume", "Bad", "Code", "Text", "Info", "Data", "Graf", "Foto", "SecureDir" }; { "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, 16, 2, "Files on disk");
addTextAndDecimal (text, buffer, 18, 2, "First block of volume"); addTextAndDecimal (text, buffer, 18, 2, "First block of volume");
GregorianCalendar calendar = Utility.getPascalDate (buffer, 20); LocalDate localDate = Utility.getPascalLocalDate (buffer, 20);
String date = calendar == null ? "--" : df.format (calendar.getTime ()); String date = localDate == null ? "--" : localDate.format (dtf);
addText (text, buffer, 20, 2, "Most recent date setting : " + date); addText (text, buffer, 20, 2, "Most recent date setting : " + date);
addTextAndDecimal (text, buffer, 22, 4, "Reserved"); addTextAndDecimal (text, buffer, 22, 4, "Reserved");
@ -71,8 +74,8 @@ class PascalCatalogSector extends AbstractSector
addText (text, buffer, ptr + 18, 4, "File name : " + name); addText (text, buffer, ptr + 18, 4, "File name : " + name);
addTextAndDecimal (text, buffer, ptr + 22, 2, "Bytes in file's last block"); addTextAndDecimal (text, buffer, ptr + 22, 2, "Bytes in file's last block");
calendar = Utility.getPascalDate (buffer, ptr + 24); localDate = Utility.getPascalLocalDate (buffer, ptr + 24);
date = calendar == null ? "--" : df.format (calendar.getTime ()); date = localDate == null ? "--" : localDate.format (dtf);
addText (text, buffer, ptr + 24, 2, "Date : " + date); addText (text, buffer, ptr + 24, 2, "Date : " + date);
ptr += PascalDisk.CATALOG_ENTRY_SIZE; ptr += PascalDisk.CATALOG_ENTRY_SIZE;

View File

@ -2,8 +2,10 @@ package com.bytezone.diskbrowser.pascal;
import java.awt.Color; import java.awt.Color;
import java.text.DateFormat; 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.ArrayList;
import java.util.GregorianCalendar;
import java.util.List; import java.util.List;
import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultMutableTreeNode;
@ -29,6 +31,7 @@ public class PascalDisk extends AbstractFormattedDisk
{ {
static final int CATALOG_ENTRY_SIZE = 26; static final int CATALOG_ENTRY_SIZE = 26;
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 final VolumeEntry volumeEntry; private final VolumeEntry volumeEntry;
private final PascalCatalogSector diskCatalogSector; private final PascalCatalogSector diskCatalogSector;
@ -232,8 +235,10 @@ public class PascalDisk extends AbstractFormattedDisk
} }
int lastByte = Utility.getShort (buffer, ptr + 22); int lastByte = Utility.getShort (buffer, ptr + 22);
GregorianCalendar date = Utility.getPascalDate (buffer, 24); // GregorianCalendar date = Utility.getPascalDate (buffer, 24);
String dateString = date == null ? "" : date.toString (); LocalDate localDate = Utility.getPascalLocalDate (buffer, 24);
String dateString = localDate == null ? ""
: localDate.format (DateTimeFormatter.ofLocalizedDate (FormatStyle.SHORT));
if (debug) if (debug)
System.out.printf ("%4d %4d %d %-15s %d %s%n", firstBlock, lastBlock, kind, System.out.printf ("%4d %4d %d %-15s %d %s%n", firstBlock, lastBlock, kind,
new String (buffer, ptr + 7, nameLength), lastByte, dateString); new String (buffer, ptr + 7, nameLength), lastByte, dateString);
@ -297,7 +302,9 @@ public class PascalDisk extends AbstractFormattedDisk
String newLine2 = newLine + newLine; String newLine2 = newLine + newLine;
String line = String line =
"---- --------------- ---- -------- ------- ---- ---- ----" + newLine; "---- --------------- ---- -------- ------- ---- ---- ----" + newLine;
String date = volumeEntry.date == null ? "--" : df.format (volumeEntry.date.getTime ());
String date = volumeEntry.localDate == null ? "--" : volumeEntry.localDate.format (dtf);
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
text.append ("File : " + getDisplayPath () + newLine2); text.append ("File : " + getDisplayPath () + newLine2);
text.append ("Volume : " + volumeEntry.name + newLine); text.append ("Volume : " + volumeEntry.name + newLine);
@ -311,16 +318,20 @@ public class PascalDisk extends AbstractFormattedDisk
FileEntry ce = (FileEntry) fe; FileEntry ce = (FileEntry) fe;
int size = ce.lastBlock - ce.firstBlock; int size = ce.lastBlock - ce.firstBlock;
usedBlocks += size; 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; int bytes = (size - 1) * 512 + ce.bytesUsedInLastBlock;
String fileType = String fileType =
ce.fileType < 0 || ce.fileType >= fileTypes.length ? "????" : fileTypes[ce.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, text.append (String.format ("%4d %-15s %-6s %8s %,8d $%03X $%03X $%03X%n", size,
ce.name, fileType, date, bytes, ce.firstBlock, ce.lastBlock, size)); ce.name, fileType, date, bytes, ce.firstBlock, ce.lastBlock, size));
} }
text.append (line); text.append (line);
text.append (String.format ("Blocks free : %3d Blocks used : %3d Total blocks : %3d%n", text.append (String.format ("Blocks free : %3d Blocks used : %3d Total blocks : %3d%n",
(volumeEntry.totalBlocks - usedBlocks), usedBlocks, volumeEntry.totalBlocks)); (volumeEntry.totalBlocks - usedBlocks), usedBlocks, volumeEntry.totalBlocks));
return new DefaultAppleFileSource (volumeEntry.name, text.toString (), this); return new DefaultAppleFileSource (volumeEntry.name, text.toString (), this);
} }
} }

View File

@ -17,9 +17,9 @@ class VolumeEntry extends CatalogEntry
{ {
super (parent, buffer); super (parent, buffer);
totalBlocks = Utility.getShort (buffer, 14); // 280 totalBlocks = Utility.getShort (buffer, 14); // 280
totalFiles = Utility.getShort (buffer, 16); totalFiles = Utility.getShort (buffer, 16);
date = Utility.getPascalDate (buffer, 20); // 2 bytes localDate = Utility.getPascalLocalDate (buffer, 20); // 2 bytes
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//

View File

@ -9,9 +9,9 @@ import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.MathContext; import java.math.MathContext;
import java.time.DateTimeException; import java.time.DateTimeException;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Arrays; import java.util.Arrays;
import java.util.GregorianCalendar;
import java.util.List; import java.util.List;
import java.util.zip.CRC32; import java.util.zip.CRC32;
import java.util.zip.Checksum; import java.util.zip.Checksum;
@ -230,7 +230,6 @@ public final class Utility
public static LocalDateTime getAppleDate (byte[] buffer, int offset) public static LocalDateTime getAppleDate (byte[] buffer, int offset)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
// int yymmdd = readShort (buffer, offset);
int yymmdd = getShort (buffer, offset); int yymmdd = getShort (buffer, offset);
if (yymmdd != 0) 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); int date = Utility.getShort (buffer, offset);
@ -446,7 +445,7 @@ public final class Utility
else else
year += 1900; year += 1900;
return new GregorianCalendar (year, month - 1, day); return LocalDate.of (year, month, day);
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//