Revision 11
| Util.java | ||
|---|---|---|
| 10 | 10 |
* @author Andrej Cimpersek |
| 11 | 11 |
*/ |
| 12 | 12 |
public class Util {
|
| 13 |
public static byte CalcXOR(byte[] data, int offset, int count) |
|
| 14 |
{
|
|
| 13 |
|
|
| 14 |
public static byte CalcXOR(byte[] data, int offset, int count) {
|
|
| 15 | 15 |
byte x = data[offset]; |
| 16 |
for (int i = 1; i < count; i++) x ^= data[offset + i]; |
|
| 16 |
for (int i = 1; i < count; i++) {
|
|
| 17 |
x ^= data[offset + i]; |
|
| 18 |
} |
|
| 17 | 19 |
return x; |
| 18 | 20 |
} |
| 19 | 21 |
|
| 20 |
private static byte CalcXOR(String data) |
|
| 21 |
{
|
|
| 22 |
byte x = (byte)(data.charAt(0)); |
|
| 23 |
for (int i = 1; i < data.length(); i++) x ^= (byte)(data.charAt(i)); |
|
| 22 |
private static byte CalcXOR(String data) {
|
|
| 23 |
byte x = (byte) (data.charAt(0)); |
|
| 24 |
for (int i = 1; i < data.length(); i++) {
|
|
| 25 |
x ^= (byte) (data.charAt(i)); |
|
| 26 |
} |
|
| 24 | 27 |
return x; |
| 25 | 28 |
} |
| 26 | 29 |
|
| ... | ... | |
| 35 | 38 |
} |
| 36 | 39 |
|
| 37 | 40 |
// Create the byte array to hold the data |
| 38 |
byte[] bytes = new byte[(int)length]; |
|
| 41 |
byte[] bytes = new byte[(int) length];
|
|
| 39 | 42 |
|
| 40 | 43 |
// Read in the bytes |
| 41 | 44 |
int offset = 0; |
| 42 | 45 |
int numRead = 0; |
| 43 | 46 |
while (offset < bytes.length |
| 44 |
&& (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
|
|
| 47 |
&& (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
|
|
| 45 | 48 |
offset += numRead; |
| 46 | 49 |
} |
| 47 | 50 |
|
| 48 | 51 |
// Ensure all the bytes have been read in |
| 49 | 52 |
if (offset < bytes.length) {
|
| 50 |
throw new IOException("Could not completely read file "+file.getName());
|
|
| 53 |
throw new IOException("Could not completely read file " + file.getName());
|
|
| 51 | 54 |
} |
| 52 | 55 |
|
| 53 | 56 |
// Close the input stream and return bytes |
Also available in: Unified diff