T
Trouble@Mill
I'm trying to read a bunch of XML from a connected socket. The 1st
time I read it, I get all the data correctly. But, the 2nd, and
subsequent times, the data is always truncated, and so the parse of
the XML fails.
Here's the piece of code in use (edited):
package com.cd3o;
public class NetworkFunctions {
private Socket socket = null;
private PrintWriter output;
private BufferedReader input;
final int iBuffSize = 1024;
private StringBuffer inputXML;
private char[] cBuff;
public NetworkFunctions() {
}
public void sendListDir(XMLFunctions xml) {
// String reply;
try {
socket = new Socket("The-Tardis", 3616);
output = new
PrintWriter(socket.getOutputStream(), true);
input = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
output.println(xml.buildListDirXML());
cBuff = new char[iBuffSize];
inputXML = new StringBuffer(iBuffSize);
do {
inputXML.append(cBuff, 0,
input.read(cBuff, 0, iBuffSize));
} while (input.ready());
// Returns true/false
System.out.println(inputXML.length());
xml.parseV(inputXML.toString());
socket.close();
}
catch (UnknownHostException e) {
System.out.println("Ooops:
UnknownHostException: " + e);
e.printStackTrace();
}
catch (IOException e) {
System.out.println("Ooops: IOException: " +
e);
e.printStackTrace();
}
}
}
This class is instantiated once into a private variable. The relevant
method is called initially from main, and following that, is always
called from a "new" Listener.
The 1st time the method is called, the length of the received XML is
51,867 bytes. Subsequent calls to the method, the XML is truncated at
11,340 bytes, or 15,120 bytes, or some other value.
It's probably some stupid newbie mistake, but I can't see what.
Cheers,
Eddie
time I read it, I get all the data correctly. But, the 2nd, and
subsequent times, the data is always truncated, and so the parse of
the XML fails.
Here's the piece of code in use (edited):
package com.cd3o;
public class NetworkFunctions {
private Socket socket = null;
private PrintWriter output;
private BufferedReader input;
final int iBuffSize = 1024;
private StringBuffer inputXML;
private char[] cBuff;
public NetworkFunctions() {
}
public void sendListDir(XMLFunctions xml) {
// String reply;
try {
socket = new Socket("The-Tardis", 3616);
output = new
PrintWriter(socket.getOutputStream(), true);
input = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
output.println(xml.buildListDirXML());
cBuff = new char[iBuffSize];
inputXML = new StringBuffer(iBuffSize);
do {
inputXML.append(cBuff, 0,
input.read(cBuff, 0, iBuffSize));
} while (input.ready());
// Returns true/false
System.out.println(inputXML.length());
xml.parseV(inputXML.toString());
socket.close();
}
catch (UnknownHostException e) {
System.out.println("Ooops:
UnknownHostException: " + e);
e.printStackTrace();
}
catch (IOException e) {
System.out.println("Ooops: IOException: " +
e);
e.printStackTrace();
}
}
}
This class is instantiated once into a private variable. The relevant
method is called initially from main, and following that, is always
called from a "new" Listener.
The 1st time the method is called, the length of the received XML is
51,867 bytes. Subsequent calls to the method, the XML is truncated at
11,340 bytes, or 15,120 bytes, or some other value.
It's probably some stupid newbie mistake, but I can't see what.
Cheers,
Eddie