对不起,我重复一个topik。但我不明白这里的答案JAXB通过套接字解组问题
https://stackoverflow.com/a/9598909/1404852 “卡夫卡”说,他通过使用XMLEventWriter修复解组块。导致建议在Stream Strings中写入,然后将它们连接到解组并不适合我。
我有这样的代码。
public class InputThread implements Runnable {
private BufferedReader in;
private String fserver; // = CharBuffer.allocate(0);
private static final Logger LOG = Logger.getLogger(InputThread.class);
private JAXBContext jaxbContext;
private Unmarshaller jaxbUnmarshaller;
private XMLProtocol protocol;
public InputThread(Socket fromserver, BufferedReader in) throws IOException, JAXBException {
jaxbContext = JAXBContext.newInstance(XMLProtocol.class);
jaxbUnmarshaller = jaxbContext.createUnmarshaller();
this.in = in;
new Thread(this);
}
public void run() {
while (true) {
try {
if (in.ready())
protocol = (XMLProtocol) jaxbUnmarshaller.unmarshal(in);
}
}
}
}
或者在服务器端我应该插入流结束?但我认为,JAXB可以做任何事情...
你看到什么异常? –
它阻止。因为它看不到流的结尾。 –
对不起,我收到异常。 DefaultValidationEventHandler:[FATAL_ERROR]:prolog中不允许使用内容。 –