From b52df7745b07aff6037586b607e565108cd397f4 Mon Sep 17 00:00:00 2001 From: Date: Thu, 11 Oct 2012 11:38:55 +0000 Subject: [PATCH] Allow extraction to a file name for the ant task --- .../webcodepro/applecommander/ui/AntTask.java | 16 +++++++++++++++- src/com/webcodepro/applecommander/ui/ac.java | 16 +++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/com/webcodepro/applecommander/ui/AntTask.java b/src/com/webcodepro/applecommander/ui/AntTask.java index 29cd24e..b116a7a 100644 --- a/src/com/webcodepro/applecommander/ui/AntTask.java +++ b/src/com/webcodepro/applecommander/ui/AntTask.java @@ -19,7 +19,9 @@ package com.webcodepro.applecommander.ui; * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +import java.io.FileOutputStream; import java.io.IOException; +import java.io.PrintStream; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Task; @@ -63,9 +65,14 @@ public class AntTask extends Task } else if (_command.equals("e") || _command.equals("g")) { + PrintStream outfile = System.out; try { - com.webcodepro.applecommander.ui.ac.getFile(_imageName, _fileName, _command.equals("e")); + if (_output != null) + { + outfile = new PrintStream(new FileOutputStream(_output)); + } + com.webcodepro.applecommander.ui.ac.getFile(_imageName, _fileName, _command.equals("e"), outfile); } catch (Exception ex) { @@ -251,6 +258,11 @@ public class AntTask extends Task _input = input; } + public void setOutput(String output) + { + _output = output; + } + public void setImageName(String imageName) { _imageName = imageName; @@ -298,6 +310,8 @@ public class AntTask extends Task String _input = null; + String _output = null; + String _command = null; String _imageName = null; diff --git a/src/com/webcodepro/applecommander/ui/ac.java b/src/com/webcodepro/applecommander/ui/ac.java index 64f191a..589797a 100644 --- a/src/com/webcodepro/applecommander/ui/ac.java +++ b/src/com/webcodepro/applecommander/ui/ac.java @@ -28,6 +28,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.PrintStream; import java.util.Iterator; import java.util.List; @@ -99,11 +100,11 @@ public class ac { } else if ("-ll".equalsIgnoreCase(args[0])) { //$NON-NLS-1$ showDirectory(args, FormattedDisk.FILE_DISPLAY_DETAIL); } else if ("-e".equalsIgnoreCase(args[0])) { //$NON-NLS-1$ - getFile(args[1], args[2], true); + getFile(args[1], args[2], true, System.out); } else if ("-x".equalsIgnoreCase(args[0])) { //$NON-NLS-1$ getFiles(args[1], (args.length > 2 ? args[2] : "")); } else if ("-g".equalsIgnoreCase(args[0])) { //$NON-NLS-1$ - getFile(args[1], args[2], false); + getFile(args[1], args[2], false, System.out); } else if ("-p".equalsIgnoreCase(args[0])) { //$NON-NLS-1$ putFile(args[1], new Name(args[2]), args[3], (args.length > 4 ? args[4] : "0x2000")); @@ -206,7 +207,10 @@ public class ac { entry.setAddress(stringToInt(address)); } formattedDisk.save(); + } else { + throw new IOException("Unable to create entry..."); } + } else throw new IOException(textBundle.get("CommandLineSDKReadOnly")); //$NON-NLS-1$ @@ -278,11 +282,13 @@ public class ac { * Get the file named filename from the disk named imageName; the file is * filtered according to its type and sent to <stdout>. */ - static void getFile(String imageName, String fileName, boolean filter) + static void getFile(String imageName, String fileName, boolean filter, PrintStream out) throws IOException { Disk disk = new Disk(imageName); Name name = new Name(fileName); FormattedDisk[] formattedDisks = disk.getFormattedDisks(); + if (out == null) + out = System.out; for (int i = 0; i < formattedDisks.length; i++) { FormattedDisk formattedDisk = formattedDisks[i]; FileEntry entry = name.getEntry(formattedDisk); @@ -292,10 +298,10 @@ public class ac { if (ff instanceof BinaryFileFilter) ff = new HexDumpFileFilter(); byte[] buf = ff.filter(entry); - System.out.write(buf, 0, buf.length); + out.write(buf, 0, buf.length); } else { byte[] buf = entry.getFileData(); - System.out.write(buf, 0, buf.length); + out.write(buf, 0, buf.length); } } else { System.err.println(textBundle.format(