1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | package Torello.Java; /** * Class Operating-System Response does is used as a return record class for the Java HTML classes * {@link Shell}, {@link GSUTIL} & {@link MSDOS}. * * <EMBED CLASS='external-html' DATA-FILE-ID=OSRES> */ public class OSResponse implements java.io.Serializable { // ******************************************************************************************** // ******************************************************************************************** // Fields // ******************************************************************************************** // ******************************************************************************************** /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ protected static final long serialVersionUID = 1; /** * This integer-value is used as a response code indicating that the process that was called * was interrupted, not completed. This should not be a common occurrence. */ public static final int INTERRUPTED = Integer.MIN_VALUE; /** * This {@code public, final, int} field will hold the "response code" reported by the * operating-system. The response-code is a number returned by the invocation of the * command to the OS. A value of {@code -1} usually signifies that the process * <I>terminated with errors</I>. If this field contains a value of * {@code Shell.INTERRUPTED}, it will mean that the process was interrupted. */ public final int response; /** * This {@code public, final, String} field will contain a transcript of the * text-{@code character} data that the Operating-System process sent to * {@code Standard-Output}. */ public final String standardOutput; /** * This {@code public, final, String} field will contain a transcript of the * text-{@code character} data that the Operating-System process sent to * {@code Standard-Error}. */ public final String errorOutput; /** Maintains a copy of the command (as a {@code String}) that produced this instance */ public final String commandStr; // ******************************************************************************************** // ******************************************************************************************** // Constructor // ******************************************************************************************** // ******************************************************************************************** /** * Builds an instance of this short return class * * @param commandStr The command which was issued that has produced this response, as a Java * {@code String} * * @param response The integer returned by the O/S command invocation. * * @param standardOutput The text/character data (as a {@code String}) sent to * {@code Standard-Output}. * * @param errorOutput The text/character data (as a {@code String}) sent to * {@code Standard-Error}. */ protected OSResponse (String commandStr, int response, String standardOutput, String errorOutput) { this.commandStr = commandStr; this.response = response; this.standardOutput = standardOutput; this.errorOutput = errorOutput; } // ******************************************************************************************** // ******************************************************************************************** // java.lang.Object and java.lang.Cloneable // ******************************************************************************************** // ******************************************************************************************** /** * Convert the information in this class into a {@code java.lang.String} * * @return A Java {@code String} representation of this class, containing * <I><B STYLE='color:red;'>abbreviated</B></I> output-data */ public String toString() { String s1 = (this.standardOutput == null) ? "null" : ((this.standardOutput.length() == 0) ? "[Zero-Length-String]" : StrPrint.abbrevEndRDSF(this.standardOutput, 80, true)); String s2 = (this.errorOutput == null) ? "null" : ((this.errorOutput.length() == 0) ? "[Zero-Length-String]" : StrPrint.abbrevEndRDSF(this.errorOutput, 80, true)); return "Command: " + StrPrint.abbrevEndRDSF(commandStr, 80, true) + '\n' + "Response: " + response + '\n' + "Standart-Output: " + s1 + '\n' + "Error-Output: " + s2; } /** * Convert the information in this class into a {@code java.lang.String} * * @return A Java {@code String} representation of this class, containing * <I><B STYLE='color:red;'>complete</B></I> output-data */ public String toStringComplete() { String s1 = (this.standardOutput == null) ? "null" : ((this.standardOutput.length() == 0) ? "[Zero-Length-String]" : StrIndent.indentAfter2ndLine(this.standardOutput, 4, true, true)); String s2 = (this.errorOutput == null) ? "null" : ((this.errorOutput.length() == 0) ? "[Zero-Length-String]" : StrIndent.indentAfter2ndLine(this.errorOutput, 4, true, true)); return "Command: " + commandStr + '\n' + "Response: " + response + '\n' + "Standart-Output: " + s1 + '\n' + "Error-Output: " + s2; } /** * Creates and returns a copy of this object. * @return a clone of this instance. */ public OSResponse clone() { return new OSResponse (this.commandStr, this.response, this.standardOutput, this.errorOutput); } /** * Returns a hash code for this instance. The hashcode produced simply invokes the * {@code hashCode()} method on the command (as a {@code String}) that was issued to produce * this instance * * @return a hash code value for this object. */ public int hashCode() { return commandStr.hashCode(); } /** * Checks whether {@code 'this'} is equal to another possible instance of {@code OSResponse}, * or a subclass of it. * * @param other This may be any Java Object, but only an instance or subclass of this class * could possibly have fields that would make an identical match to {@code 'this'} instance. * * @return {@code TRUE} if and only if the contents of the fields inside {@code 'this'} * instance are identical to the fields in {@code 'other'} */ public boolean equals(Object other) { if (other == null) return false; if (! OSResponse.class.isAssignableFrom(other.getClass())) return false; OSResponse o = (OSResponse) other; return (this.response == o.response) && (this.commandStr.equals(o.commandStr)) && (this.standardOutput.equals(o.standardOutput)) && (this.errorOutput.equals(o.errorOutput)); } } |