I have this server that has to receive a xml file from a client. All that works fine and my server creates a new xml file. After that I try to use JAXB to read from the XML file but I get the SAXParseException. I've tried with multiple files and in another class it works just fine,but not in the Server class
private void saveFile(Socket clientSock) throws IOException, JAXBException {
DataInputStream dis = new DataInputStream(clientSock.getInputStream());
FileOutputStream fos = new FileOutputStream("testfile.xml");
byte[] buffer = new byte[4096];
int filesize = 15123; // Send file size in separate msg
int read = 0;
int totalRead = 0;
int remaining = filesize;
while((read = dis.read(buffer, 0, Math.min(buffer.length, remaining))) > 0) {
totalRead += read;
remaining -= read;
System.out.println("read " + totalRead + " bytes.");
fos.write(buffer, 0, read);
}
fos.close();
dis.close();
JAXBContext jac;
jac = JAXBContext.newInstance(Product.class,Order.class,Orders.class,Products.class);
Marshaller jaxbMarshaller = jac.createMarshaller();
jaxbMarshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true );
Unmarshaller jaxbUnmarshaller = jac.createUnmarshaller();
**Orders newOrders = (Orders)jaxbUnmarshaller.unmarshal( new File("testfile.xml"));**
System.out.println( newOrders.getOrders().get(1).getId() );