return (char) b;
}
protected static void readAsHex(ZipFile zipFile, ZipEntry entry, Writer out, long limit, int groupsOf8BytesPerLine, IProgressMonitor monitor) throws IOException {
SubMonitor progress = createProgressMonitor(entry, limit, monitor);
boolean limitReached = false;
long offsetInFile = 0;
int bytesPerLine = groupsOf8BytesPerLine * 8;
int asciiPosition = 0;
char[] asciiBuffer = new char[bytesPerLine + (2 * (groupsOf8BytesPerLine - 1))];
int bytePosition = 0;
byte[] buffer = new byte[1024];
InputStream stream = zipFile.getInputStream(entry);
try {
long total = 0;
while (true) {
if (progress.isCanceled())
return;
int bytesRead = stream.read(buffer, 0, 1024);
if (bytesRead < 0)
break;
for (int i = 0; i < bytesRead; i++) {
if (bytePosition == 0) {
String s = String.format("0x%04x ", offsetInFile);
out.write(s);
offsetInFile += bytesPerLine;
}
asciiBuffer[asciiPosition] = byteToChar(buffer[i]);
asciiPosition++;
out.write(pseudo[(buffer[i] & 0xf0) >>> 4]); // Convert to a string character
out.write(pseudo[(buffer[i] & 0x0f)]); // convert the nibble to a String Character
out.write(' ');
bytePosition++;
/* do a linebreak after the required number of bytes */
if (bytePosition >= bytesPerLine) {
out.write(' ');
out.write(asciiBuffer);
out.write('\n');
asciiPosition = 0;
bytePosition = 0;
}
/* put 2 extra spaces between bytes */
if ((bytePosition > 0) && (bytePosition % 8 == 0)) {
asciiBuffer[asciiPosition++] = ' ';
asciiBuffer[asciiPosition++] = ' ';
out.write(' ');
}
}
total += bytesRead;
progress.worked(bytesRead);
if (limit >= 0 && total >= limit) {
limitReached = true;
return;
}
}