/** * Wrap an XMLEventWriter around that StringWriter. */ private XMLEventWriter createXmlEventWriter(StringWriter stringWriter) throws FactoryConfigurationError, XMLStreamException { return new IndentingXMLEventWriter(XMLOutputFactory.newInstance() .createXMLEventWriter(stringWriter)); } }
/** * Create an XMLEventWriter for this file. Make it a pretty, indenting * writer. */ private XMLEventWriter createXmlEventWriter(FileWriter fileWriter) throws FactoryConfigurationError, XMLStreamException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); return new IndentingXMLEventWriter(factory .createXMLEventWriter(fileWriter)); }
/** * Create an XMLEventWriter for this file. Make it a pretty, indenting * writer. */ private XMLEventWriter createXmlEventWriter(FileWriter fileWriter) throws FactoryConfigurationError, XMLStreamException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); return new IndentingXMLEventWriter(factory .createXMLEventWriter(fileWriter)); }
/** * Wrap an XMLEventWriter around that StringWriter. */ private XMLEventWriter createXmlEventWriter(StringWriter stringWriter) throws FactoryConfigurationError, XMLStreamException { return new IndentingXMLEventWriter(XMLOutputFactory.newInstance() .createXMLEventWriter(stringWriter)); } }
protected XMLEventWriter filter(XMLEventWriter writer) { if (indenting) { IndentingXMLEventWriter indenter = new IndentingXMLEventWriter(writer); indenter.setNewLine(newLine); indenter.setIndent(indent); writer = indenter; } return writer; }
private void initializeReaderAndWriter(InputStream inputStream, OutputStream outputStream, boolean outputAsXmlFragment) throws WLFormatException { if (inputStream != null) { try { XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); xmlEventReader = xmlInputFactory.createXMLEventReader(inputStream, "UTF-8"); } catch (XMLStreamException e) { throw new WLFormatException(e.getMessage(), e); } } if (outputStream != null) { try { XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance(); xmlEventWriter = new IndentingXMLEventWriter(xmlOutputFactory.createXMLEventWriter(outputStream, "UTF-8")); } catch (XMLStreamException e) { throw new WLFormatException(e.getMessage(), e); } } xmlReaderWriter = new XmlReaderWriter(xmlEventReader, xmlEventWriter); xmlReaderWriter.setOutputAsXmlFragment(outputAsXmlFragment); }
private XMLEventWriter createXmlWriter() throws FactoryConfigurationError, XMLStreamException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); return new IndentingXMLEventWriter(factory .createXMLEventWriter(xmlStringWriter)); }
public MockJournalWriter(Map<String, String> parameters, String role, ServerInterface server) throws XMLStreamException, FactoryConfigurationError { super(parameters, role, server); xmlWriter = new IndentingXMLEventWriter(XMLOutputFactory.newInstance() .createXMLEventWriter(stringWriter)); }
private void initializeReaderAndWriter(InputStream inputStream, OutputStream outputStream, boolean outputAsXmlFragment) throws WLFormatException { if (inputStream != null) { try { XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); xmlEventReader = xmlInputFactory.createXMLEventReader(inputStream, "UTF-8"); } catch (XMLStreamException e) { throw new WLFormatException(e.getMessage(), e); } } if (outputStream != null) { try { XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance(); xmlEventWriter = new IndentingXMLEventWriter(xmlOutputFactory.createXMLEventWriter(outputStream, "UTF-8")); } catch (XMLStreamException e) { throw new WLFormatException(e.getMessage(), e); } } xmlReaderWriter = new XmlReaderWriter(xmlEventReader, xmlEventWriter); xmlReaderWriter.setOutputAsXmlFragment(outputAsXmlFragment); }
private void initializeReaderAndWriter(InputStream inputStream, OutputStream outputStream, boolean outputAsXmlFragment) throws WLFormatException { if (inputStream != null) { try { XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); xmlEventReader = xmlInputFactory.createXMLEventReader(inputStream, "UTF-8"); } catch (XMLStreamException e) { throw new WLFormatException(e.getMessage(), e); } } if (outputStream != null) { try { XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance(); xmlEventWriter = new IndentingXMLEventWriter(xmlOutputFactory.createXMLEventWriter(outputStream, "UTF-8")); } catch (XMLStreamException e) { throw new WLFormatException(e.getMessage(), e); } } xmlReaderWriter = new XmlReaderWriter(xmlEventReader, xmlEventWriter); xmlReaderWriter.setOutputAsXmlFragment(outputAsXmlFragment); }
private void initializeReaderAndWriter( InputStream inputStream, OutputStream outputStream, boolean outputAsXmlFragment) throws WLFormatException { if (inputStream != null) { try { XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); xmlEventReader = xmlInputFactory.createXMLEventReader(inputStream, "UTF-8"); } catch (XMLStreamException e) { throw new WLFormatException(e.getMessage(), e); } } if (outputStream != null) { try { XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance(); xmlEventWriter = new IndentingXMLEventWriter(xmlOutputFactory.createXMLEventWriter(outputStream, "UTF-8")); } catch (XMLStreamException e) { throw new WLFormatException(e.getMessage(), e); } } xmlReaderWriter = new XmlReaderWriter(xmlEventReader, xmlEventWriter); xmlReaderWriter.setOutputAsXmlFragment(outputAsXmlFragment); }
/** * Get the name of the journal file from the server parameters, create the * file, wrap it in an XMLEventWriter, and initialize it with a document * header. */ public SingleFileJournalWriter(Map<String, String> parameters, String role, ServerInterface server) throws JournalException { super(parameters, role, server); if (!parameters.containsKey(PARAMETER_JOURNAL_FILENAME)) { throw new JournalException("Parameter '" + PARAMETER_JOURNAL_FILENAME + "' not set."); } try { out = new FileWriter(parameters.get(PARAMETER_JOURNAL_FILENAME)); XMLOutputFactory factory = XMLOutputFactory.newInstance(); writer = new IndentingXMLEventWriter(factory .createXMLEventWriter(out)); } catch (IOException e) { throw new JournalException(e); } catch (XMLStreamException e) { throw new JournalException(e); } }
/** * Get the name of the journal file from the server parameters, create the * file, wrap it in an XMLEventWriter, and initialize it with a document * header. */ public SingleFileJournalWriter(Map<String, String> parameters, String role, ServerInterface server) throws JournalException { super(parameters, role, server); if (!parameters.containsKey(PARAMETER_JOURNAL_FILENAME)) { throw new JournalException("Parameter '" + PARAMETER_JOURNAL_FILENAME + "' not set."); } try { out = new FileWriter(parameters.get(PARAMETER_JOURNAL_FILENAME)); XMLOutputFactory factory = XMLOutputFactory.newInstance(); writer = new IndentingXMLEventWriter(factory .createXMLEventWriter(out)); } catch (IOException e) { throw new JournalException(e); } catch (XMLStreamException e) { throw new JournalException(e); } }
new IndentingXMLEventWriter(factory.createXMLEventWriter(new BufferedWriter(stringBuilderWriter)));
/** * check state, send the open request, open a very special writer, write the * file opening, set state */ @Override public void openFile(String repositoryHash, String filename, Date currentDate) throws JournalException { try { super.testStateChange(State.FILE_OPEN); writer = new RmiTransportWriter(receiver, repositoryHash, filename); xmlWriter = new IndentingXMLEventWriter(XMLOutputFactory .newInstance() .createXMLEventWriter(new BufferedWriter(writer, bufferSize))); parent.writeDocumentHeader(xmlWriter, repositoryHash, currentDate); super.setState(State.FILE_OPEN); } catch (XMLStreamException e) { throw new JournalException(e); } catch (FactoryConfigurationError e) { throw new JournalException(e); } }
/** * check state, send the open request, open a very special writer, write the * file opening, set state */ @Override public void openFile(String repositoryHash, String filename, Date currentDate) throws JournalException { try { super.testStateChange(State.FILE_OPEN); writer = new RmiTransportWriter(receiver, repositoryHash, filename); xmlWriter = new IndentingXMLEventWriter(XMLOutputFactory .newInstance() .createXMLEventWriter(new BufferedWriter(writer, bufferSize))); parent.writeDocumentHeader(xmlWriter, repositoryHash, currentDate); super.setState(State.FILE_OPEN); } catch (XMLStreamException e) { throw new JournalException(e); } catch (FactoryConfigurationError e) { throw new JournalException(e); } }
@Override public void openFile(String repositoryHash, String filename, Date currentDate) throws JournalException { howManyOpenFileRequests++; this.repositoryHash = repositoryHash; this.filename = filename; this.currentDate = currentDate; try { stringWriter = new StringWriter(); xmlWriter = new IndentingXMLEventWriter(XMLOutputFactory.newInstance() .createXMLEventWriter(stringWriter)); } catch (XMLStreamException e) { throw new JournalException(e); } catch (FactoryConfigurationError e) { throw new JournalException(e); } }
/** * On a request to open the file, * <ul> * <li>check that we are in a valid state,</li> * <li>create the file,</li> * <li>create the {@link XMLEventWriter} for use on the file,</li> * <li>ask the parent to write the header to the file,</li> * <li>set the state.</li> * </ul> */ @Override public void openFile(String repositoryHash, String filename, Date currentDate) throws JournalException { try { super.testStateChange(State.FILE_OPEN); journalFile = new TransportOutputFile(directory, filename); xmlWriter = new IndentingXMLEventWriter(XMLOutputFactory.newInstance() .createXMLEventWriter(journalFile.open())); parent.writeDocumentHeader(xmlWriter, repositoryHash, currentDate); super.setState(State.FILE_OPEN); } catch (FactoryConfigurationError e) { throw new JournalException(e); } catch (XMLStreamException e) { throw new JournalException(e); } catch (IOException e) { throw new JournalException(e); } }
@Test public void testSizeEstimation() throws JournalException, XMLStreamException, FactoryConfigurationError { MockMulticastJournalWriter mjw = new MockMulticastJournalWriter(parameters, role, server); mjw.setCheckParametersForValidity(false); JournalEntrySizeEstimator estimator = new JournalEntrySizeEstimator(mjw); for (CreatorJournalEntry journalEntry : journalEntries) { StringWriter stringWriter = new StringWriter(); XMLEventWriter xmlEventWriter = new IndentingXMLEventWriter(XMLOutputFactory.newInstance() .createXMLEventWriter(stringWriter)); mjw.writeJournalEntry(journalEntry, xmlEventWriter); long estimatedSize = estimator.estimateSize(journalEntry); assertSizesAreReallyClose(stringWriter.getBuffer().length(), estimatedSize); } }
/** * On a request to open the file, * <ul> * <li>check that we are in a valid state,</li> * <li>create the file,</li> * <li>create the {@link XMLEventWriter} for use on the file,</li> * <li>ask the parent to write the header to the file,</li> * <li>set the state.</li> * </ul> */ @Override public void openFile(String repositoryHash, String filename, Date currentDate) throws JournalException { try { super.testStateChange(State.FILE_OPEN); journalFile = new TransportOutputFile(directory, filename); xmlWriter = new IndentingXMLEventWriter(XMLOutputFactory.newInstance() .createXMLEventWriter(journalFile.open())); parent.writeDocumentHeader(xmlWriter, repositoryHash, currentDate); super.setState(State.FILE_OPEN); } catch (FactoryConfigurationError e) { throw new JournalException(e); } catch (XMLStreamException e) { throw new JournalException(e); } catch (IOException e) { throw new JournalException(e); } }