对不起,我重复一个话题。但我不明白这里的答案
https://stackoverflow.com/a/9598909/1404852 “Kafka”说他使用 XMLEventWriter 修复了解组块。导致建议写入流字符串,然后将它们连接到不适合我的解组。
我有这样的代码。
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 可以做任何事情......