@SuppressWarnings("unchecked") @Override public void read(Transferable t, Drawing drawing, boolean replace) throws UnsupportedFlavorException, IOException { try { Drawing d = (Drawing) t.getTransferData(dataFlavor); if (replace) { for (Map.Entry<AttributeKey, Object> e : d.getAttributes().entrySet()) { drawing.set(e.getKey(), e.getValue()); } } for (Figure f : d.getChildren()) { drawing.add(f); } } catch (Throwable th) { th.printStackTrace(); } }
@SuppressWarnings("unchecked") @Override public void read(InputStream in, Drawing drawing, boolean replace) throws IOException { try { ObjectInputStream oin = new ObjectInputStream(in); Drawing d = (Drawing) oin.readObject(); if (replace) { for (Map.Entry<AttributeKey, Object> e : d.getAttributes().entrySet()) { drawing.set(e.getKey(), e.getValue()); } } for (Figure f : d.getChildren()) { drawing.add(f); } } catch (ClassNotFoundException ex) { IOException ioe = new IOException("Couldn't read drawing."); ioe.initCause(ex); throw ioe; } }
/** * All other write methods delegate their work to here. */ public void write(OutputStream out, Drawing drawing, java.util.List<Figure> figures) throws IOException { document = new XMLElement("svg", SVG_NAMESPACE); document.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink"); document.setAttribute("version", "1.2"); document.setAttribute("baseProfile", "tiny"); writeViewportAttributes(document, drawing.getAttributes()); initStorageContext(document); defs = new XMLElement("defs"); document.addChild(defs); for (Figure f : figures) { writeElement(document, f); } // Write XML prolog PrintWriter writer = new PrintWriter( new OutputStreamWriter(out, "UTF-8")); writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); // Write XML content XMLWriter xmlWriter = new XMLWriter(writer); xmlWriter.write(document, isPrettyPrint); // Flush writer writer.flush(); document.dispose(); }