Make some methods more visible from the outside, as part of integrating into an ant task.

This commit is contained in:
2012-07-08 22:20:19 +00:00
parent 14ed4324d6
commit 4580a7183f
1 changed files with 47 additions and 3 deletions

View File

@ -23,8 +23,10 @@ package com.webcodepro.applecommander.ui;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.List;
@ -106,9 +108,9 @@ public class ac {
} else if ("-d".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
deleteFile(args[1], new Name(args[2]));
} else if ("-k".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
setFileLocked(args[1], new Name(args[2]), true);
setFileLocked(args[1], args[2], true);
} else if ("-u".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
setFileLocked(args[1], new Name(args[2]), false);
setFileLocked(args[1], args[2], false);
} else if ("-n".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
setDiskName(args[1], args[2]);
} else if ("-cc65".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
@ -136,6 +138,40 @@ public class ac {
}
}
/**
* Put fileName from the local filesytem into the file named fileOnImageName on the disk named imageName;
* Note: only volume level supported; input size unlimited.
*/
public static void putFile(String fileName, String imageName, String fileOnImageName, String fileType,
String address) throws IOException, DiskFullException {
Name name = new Name(fileOnImageName);
File file = new File(fileName);
if (!file.canRead())
{
throw new IOException("Unable to read input file named "+fileName+".");
}
ByteArrayOutputStream buf = new ByteArrayOutputStream();
byte[] inb = new byte[1024];
int byteCount = 0;
InputStream is = new FileInputStream(file);
while ((byteCount = is.read(inb)) > 0) {
buf.write(inb, 0, byteCount);
}
Disk disk = new Disk(imageName);
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
FormattedDisk formattedDisk = formattedDisks[0];
FileEntry entry = name.createEntry(formattedDisk);
if (entry != null) {
entry.setFiletype(fileType);
entry.setFilename(name.name);
entry.setFileData(buf.toByteArray());
if (entry.needsAddress()) {
entry.setAddress(stringToInt(address));
}
formattedDisk.save();
}
}
/**
* Put <stdin> into the file named fileName on the disk named imageName;
* Note: only volume level supported; input size unlimited.
@ -367,6 +403,14 @@ public class ac {
}
}
/**
* Set the lockState of the file named fileName on the disk named imageName.
* Proposed by David Schmidt.
*/
public static void setFileLocked(String imageName, String name, boolean lockState) throws IOException {
setFileLocked(imageName, new Name(name), lockState);
}
/**
* Set the lockState of the file named fileName on the disk named imageName.
* Proposed by David Schmidt.
@ -392,7 +436,7 @@ public class ac {
* Set the volume name for a given disk image. Only effective for ProDOS or
* Pascal disks; others ignored. Proposed by David Schmidt.
*/
static void setDiskName(String imageName, String volName)
public static void setDiskName(String imageName, String volName)
throws IOException {
Disk disk = new Disk(imageName);
FormattedDisk[] formattedDisks = disk.getFormattedDisks();