String toolName = "";\r
List<Object> toolArgList = new ArrayList<Object>();\r
String outputPath;\r
- String outPutFileName ;\r
+ File outputFile ;\r
List<Input> inputFiles = new ArrayList<Input>();\r
\r
/**\r
@param buffer The buffer to put the result with alignment\r
**/\r
public void toBuffer (DataOutputStream buffer){\r
- File OutputFile;\r
- byte data;\r
-\r
///\r
/// call extern tool\r
///\r
///\r
/// check if file exist\r
///\r
- OutputFile = new File (this.outPutFileName);\r
- long fileLen = OutputFile.length();\r
- if (!OutputFile.exists()) {\r
- throw new BuildException("The file " + outPutFileName + " does not exist!\n");\r
+ //File OutputFile = new File (this.outPutFileName);\r
+ if (!outputFile.exists()) {\r
+ throw new BuildException("The file " + outputFile.getPath() + " does not exist!\n");\r
}\r
\r
///\r
/// Read output file and write it's cotains to buffer\r
///\r
+ FileInputStream fs = null;\r
+ DataInputStream in = null;\r
try {\r
- FileInputStream fs = new FileInputStream (this.outPutFileName);\r
- DataInputStream In = new DataInputStream (fs);\r
-\r
- int i = 0;\r
- while (i < fileLen) {\r
- data = In.readByte();\r
- buffer.writeByte(data);\r
- i ++;\r
- }\r
+ fs = new FileInputStream (outputFile);\r
+ in = new DataInputStream (fs);\r
+\r
+\r
+ int fileLen = (int)outputFile.length();\r
+ byte[] data = new byte[fileLen];\r
+ in.read(data);\r
+ buffer.write(data, 0, fileLen);\r
\r
///\r
/// 4 byte alignment\r
fileLen++;\r
buffer.writeByte(0);\r
}\r
- In.close();\r
-\r
} catch (Exception e) {\r
System.out.print(e.getMessage());\r
throw new BuildException("Tool call, toBuffer failed!\n");\r
+ } finally {\r
+ try {\r
+ if (in != null) {\r
+ in.close();\r
+ }\r
+ if (fs != null) {\r
+ fs.close();\r
+ }\r
+ } catch (Exception e) {\r
+ System.out.println("WARNING: Cannot close " + outputFile.getPath());\r
+ }\r
}\r
}\r
\r
///\r
/// input files for tools\r
///\r
- argument = argument + "-i ";\r
+ argument += " -i ";\r
while (inputIter.hasNext()) {\r
file = (Input)inputIter.next();\r
- argument = argument + file.getFile() + " ";\r
+ argument += file.toString(" ");\r
}\r
\r
- outPutFileName = outputPath + File.separatorChar + (new File(file.getFile())).getName() + ".crc";\r
- argument = argument + " -o " + outPutFileName; \r
-\r
try {\r
+ outputFile = File.createTempFile("temp", ".crc", new File(outputPath));\r
+ argument = argument + " -o " + outputFile.getPath();\r
\r
///\r
/// execute command line\r