partial writing

This commit is contained in:
Denis Molony 2021-04-16 21:08:59 +10:00
parent b0b00b4029
commit 6aa882ecbd
4 changed files with 72 additions and 9 deletions

View File

@ -187,7 +187,15 @@ public class DiskFactory
// System.out.printf ("Total files: %d%n", totalFiles); // System.out.printf ("Total files: %d%n", totalFiles);
if (totalFiles == 0) if (totalFiles == 0)
return null; return null;
nuFX.getDiskBuffer ();
File tmp = File.createTempFile (suffix, null);
FileOutputStream fos = new FileOutputStream (tmp);
fos.write (nuFX.getDiskBuffer ());
fos.close ();
tmp.deleteOnExit ();
file = tmp;
suffix = "po";
compressed = true;
} }
catch (IOException e) catch (IOException e)
{ {

View File

@ -112,7 +112,7 @@ public class ProdosDisk
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
FileEntry addFile (String path, int type) public FileEntry addFile (String path, int type, byte[] dataBuffer)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
String[] subdirectories; String[] subdirectories;
@ -160,6 +160,8 @@ public class ProdosDisk
fileEntry.headerPointer = catalogBlockNo; fileEntry.headerPointer = catalogBlockNo;
fileEntry.fileType = 4; // text fileEntry.fileType = 4; // text
fileEntry.writeFile (dataBuffer);
fileEntry.write (); fileEntry.write ();
updateFileCount (fileEntry.headerPointer); updateFileCount (fileEntry.headerPointer);
@ -169,6 +171,16 @@ public class ProdosDisk
return null; return null;
} }
// ---------------------------------------------------------------------------------//
public void close ()
// ---------------------------------------------------------------------------------//
{
writeVolumeBitMap ();
volumeDirectoryHeader.write ();
for (SubdirectoryHeader subdirectoryHeader : subdirectoryHeaders.values ())
subdirectoryHeader.write ();
}
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
private FileEntry searchDirectory (int blockNo, String fileName) private FileEntry searchDirectory (int blockNo, String fileName)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@ -351,4 +363,11 @@ public class ProdosDisk
} }
} }
} }
// ---------------------------------------------------------------------------------//
public byte[] getBuffer ()
// ---------------------------------------------------------------------------------//
{
return buffer;
}
} }

View File

@ -7,6 +7,8 @@ import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.bytezone.diskbrowser.prodos.write.ProdosDisk;
// -----------------------------------------------------------------------------------// // -----------------------------------------------------------------------------------//
public class NuFX public class NuFX
// -----------------------------------------------------------------------------------// // -----------------------------------------------------------------------------------//
@ -24,13 +26,7 @@ public class NuFX
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
buffer = Files.readAllBytes (path); buffer = Files.readAllBytes (path);
readBuffer ();
}
// ---------------------------------------------------------------------------------//
private void readBuffer ()
// ---------------------------------------------------------------------------------//
{
masterHeader = new MasterHeader (buffer); masterHeader = new MasterHeader (buffer);
int dataPtr = 48; int dataPtr = 48;
@ -86,7 +82,37 @@ public class NuFX
} }
else if (totalFiles > 0) else if (totalFiles > 0)
{ {
listFiles (); // listFiles ();
try
{
ProdosDisk disk = new ProdosDisk (1600, "DISKBROWSER");
int count = 0;
for (Record record : records)
{
if (record.hasFile ())
{
String fileName = record.getFileName ();
int fileSize = record.getFileSize ();
int fileType = record.getFileType ();
int eof = record.getUncompressedSize ();
byte[] buffer = record.getData ();
System.out.printf ("%3d %-35s %,7d %d %,7d %d%n", ++count, fileName,
fileSize, fileType, eof, buffer.length);
if (fileType == 4 && count > 10 && count < 16)
{
disk.addFile (fileName, fileType, buffer);
}
}
}
disk.close ();
return disk.getBuffer ();
}
catch (IOException e)
{
e.printStackTrace ();
}
} }
return null; return null;

View File

@ -193,6 +193,16 @@ class Record
return 0; return 0;
} }
// ---------------------------------------------------------------------------------//
byte[] getData ()
// ---------------------------------------------------------------------------------//
{
for (Thread thread : threads)
if (thread.hasFile ())
return thread.getData ();
return null;
}
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@Override @Override
public String toString () public String toString ()