This discussion is archived
4 Replies Latest reply: Dec 7, 2012 7:59 AM by 945854 RSS

Receive octal data from InputStream - instead hexadecimal

945854 Newbie
Currently Being Moderated
Hi,

I'm creating a Java SE 7 desktop application which must copy what an already implemented PHP one does. To make sure that every thing works as intended in the Java application, I've got this method:

+public static void printValues(String string) {+
System.out.println("\nPRINTVALUES: ");
System.out.println("Length: "string.length());+
for (int i = 0; i < string.length(); i+) {+
System.out.print("x" ((int)string.charAt(i)));+
+}+
System.out.print("\n");
System.exit(-1);
+}+

which I use for debugging purposes. I've got a similar method in PHP which does exactly the same, so I can use both to compare outputs and decide if everything has gone right until the methods are called. This method has been perfect since I started: I get the octal bytes in both Java and PHP and I can compare them. But there's a moment in the application where it sends some data to a server and has to process it reply. By using this method, I've already checked that the data sent in Java is exactly equal to the one sent in PHP, but they're not receiving the same reply, and I can't even use the above method to make a comparison because the Java application is printing hexadecimal values instead octal ones. This is the method I'm using to get the reply:

private String readData() {
String buff = "", data;
byte[] bytes = new byte[1024];
InputStream input = null;

try {
input = this.socketChannel.socket().getInputStream();
} catch (IOException ex) {
//Exception handling useless code
}

int howManyRead = -1;
try {
howManyRead = input.read(bytes);
System.out.println(howManyRead);
}
} catch (IOException ex) {
//Exception handling useless code
}

byte[] newBytes = new byte[howManyRead];
System.arraycopy(bytes, 0, newBytes, 0, howManyRead);

String ret = new String(newBytes));
org.Main.printValues(ret);

return ret; //Currently unreachable statement, the output for the comparison is performed in the above sentence which includes a System.exit(-1) invocation.

Could anybody please help me in retrieving the data as actually octal bytes so I get the data in same format as in PHP (octal)?

Thanks in advance.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points