Code example for StreamSource

0
public class Disk { 
	public static Object read(Class<?> cls, File path) {
		try { 
			JAXBContext jc = JAXBContext.newInstance(cls);
			Unmarshaller u = jc.createUnmarshaller();
			return u.unmarshal(new StreamSource(path), cls).getValue();
		} catch (JAXBException e) {
			Logger.getLogger(cls.getSimpleName()).log(Level.WARNING, "JAXBException", e);
			return null; 
		} 
	} 
 
	public static void save(File path, Object jaxb) throws Exception {
		JAXBContext context = JAXBContext.newInstance(jaxb.getClass());
 
		Marshaller m = context.createMarshaller();
		m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
 
		FileOutputStream out = new FileOutputStream(path);
		m.marshal(jaxb, out);
		out.close();