1 package de.masters_of_disaster.ant.tasks.ar; 2 3 6 public class ArUtils { 7 16 public static long parseOctal(byte[] header, int offset, int length) { 17 long result = 0; 18 int end = offset + length; 19 20 for (int i=offset ; i<end ; i++) { 21 if (header[i] == (byte) ' ') { 22 break; 23 } 24 result = (result << 3) + (header[i] - '0'); 25 } 26 27 return result; 28 } 29 30 38 public static StringBuffer parseName(byte[] header, int offset, int length) { 39 StringBuffer result = new StringBuffer (length); 40 int end = offset + length; 41 42 for (int i=offset ; i<end ; i++) { 43 if (header[i] == ' ') { 44 break; 45 } 46 47 result.append((char) header[i]); 48 } 49 50 return result; 51 } 52 53 62 public static int getNameBytes(StringBuffer name, byte[] buf, int offset, int length) { 63 int i; 64 int c = name.length(); 65 66 for (i=0 ; i<length && i<c ; i++) { 67 buf[offset+i] = (byte) name.charAt(i); 68 } 69 70 while (i<length) { 71 buf[offset+i] = (byte) ' '; 72 i++; 73 } 74 75 return offset + length; 76 } 77 78 87 public static int getLongBytes(long value, byte[] buf, int offset, int length) { 88 int i; 89 String tmp = Long.toString(value); 90 int c = tmp.length(); 91 92 for (i=0 ; i<length && i<c ; i++) { 93 buf[offset+i] = (byte) tmp.charAt(i); 94 } 95 96 while (i<length) { 97 buf[offset+i] = (byte) ' '; 98 i++; 99 } 100 101 return offset + length; 102 } 103 104 113 public static int getIntegerBytes(int value, byte[] buf, int offset, int length) { 114 int i; 115 String tmp = Integer.toString(value); 116 int c = tmp.length(); 117 118 for (i=0 ; i<length && i<c ; i++) { 119 buf[offset+i] = (byte) tmp.charAt(i); 120 } 121 122 while (i<length) { 123 buf[offset+i] = (byte) ' '; 124 i++; 125 } 126 127 return offset + length; 128 } 129 130 139 public static int getOctalBytes(long value, byte[] buf, int offset, int length) { 140 int i; 141 String tmp = Long.toOctalString(value); 142 int c = tmp.length(); 143 144 for (i=0 ; i<length && i<c ; i++) { 145 buf[offset+i] = (byte) tmp.charAt(i); 146 } 147 148 while (i<length) { 149 buf[offset+i] = (byte) ' '; 150 i++; 151 } 152 153 return offset + length; 154 } 155 } 156 | Popular Tags |