| | |
| | | IntegerArgument timeout = null; |
| | | StringArgument logFilePath = null; |
| | | StringArgument targetFilePath = null; |
| | | StringArgument outputFilePath = null; |
| | | |
| | | String toolDescription = getMessage(MSGID_WAIT4DEL_TOOL_DESCRIPTION); |
| | | ArgumentParser argParser = new ArgumentParser(CLASS_NAME, toolDescription, |
| | |
| | | argParser.addArgument(logFilePath); |
| | | |
| | | |
| | | outputFilePath = new StringArgument("outputfile", 'o', "outputFile", |
| | | false, false, |
| | | true, "{path}", null, null, |
| | | MSGID_WAIT4DEL_DESCRIPTION_OUTPUT_FILE); |
| | | argParser.addArgument(outputFilePath); |
| | | |
| | | |
| | | timeout = new IntegerArgument("timeout", 't', "timeout", true, false, |
| | | true, "{seconds}", 60, null, true, 0, false, |
| | | 0, MSGID_WAIT4DEL_DESCRIPTION_TIMEOUT); |
| | |
| | | } |
| | | |
| | | |
| | | // If an output file was specified and we could open the log file, open it |
| | | // and append data to it. |
| | | RandomAccessFile outputFile = null; |
| | | long outputFileOffset = 0L; |
| | | if (logFile != null) |
| | | { |
| | | if (outputFilePath.isPresent()) |
| | | { |
| | | try |
| | | { |
| | | File f = new File(outputFilePath.getValue()); |
| | | if (f.exists()) |
| | | { |
| | | outputFile = new RandomAccessFile(f, "rw"); |
| | | outputFileOffset = outputFile.length(); |
| | | outputFile.seek(outputFileOffset); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | int msgID = MSGID_WAIT4DEL_CANNOT_OPEN_OUTPUT_FILE; |
| | | String message = getMessage(msgID, outputFilePath.getValue(), |
| | | String.valueOf(e)); |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | |
| | | outputFile = null; |
| | | } |
| | | } |
| | | } |
| | | // Figure out when to stop waiting. |
| | | long stopWaitingTime; |
| | | try |
| | |
| | | int bytesRead = logFile.read(logBuffer); |
| | | if (bytesRead > 0) |
| | | { |
| | | System.out.write(logBuffer, 0, bytesRead); |
| | | System.out.flush(); |
| | | if (outputFile == null) |
| | | { |
| | | System.out.write(logBuffer, 0, bytesRead); |
| | | System.out.flush(); |
| | | } |
| | | else |
| | | { |
| | | // Write on the file. |
| | | // TODO |
| | | outputFile.write(logBuffer, 0, bytesRead); |
| | | |
| | | } |
| | | logFileOffset += bytesRead; |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | if (outputFile != null) |
| | | { |
| | | try |
| | | { |
| | | outputFile.close(); |
| | | } |
| | | catch (Throwable t) {} |
| | | } |
| | | |
| | | if (targetFile.exists()) |
| | | { |