Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JAXB通过套接字解组问题_Java_Sockets_Jaxb_Unmarshalling - Fatal编程技术网

Java JAXB通过套接字解组问题

Java JAXB通过套接字解组问题,java,sockets,jaxb,unmarshalling,Java,Sockets,Jaxb,Unmarshalling,对不起,伙计们,我重复了一个主题。但我不明白这里有什么答案 “Kafka”说他使用XMLEventWriter修复了解组块。使建议在流字符串中写入,然后将其浓缩以解组不适合我 我有这样的代码 public class InputThread implements Runnable { private BufferedReader in; private String fserver; // = CharBuffer.allocate(0); private stat

对不起,伙计们,我重复了一个主题。但我不明白这里有什么答案

“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可以做任何事情…

流可以预先编码长度,它可以以一个特殊字符(如EOF)结束,或者服务器可以关闭连接。如果预先对长度进行编码,则可能需要构造某种特殊的输入流,在输入了那么多字符后,该流会自动关闭。这类似于HTTP的内容长度头和管道。如果以EOF这样的特殊字符结尾,则必须将该字符视为保留字符。同样,如上所述,您需要一个特殊的输入流。这一次,当它读取特殊字符时,它是接近的。它不能出现在数据中,因为它现在是元字符。关闭连接就像没有管道的HTTP。

您看到了什么异常?它会阻塞。因为它无法看到流的结尾。很抱歉,我收到异常。DefaultValidationEventHandler:[致命错误]:在服务器端的prolog.Hmm中不允许包含内容。在封送到输出流之后,我应该写EOF?