List of usage examples for javax.xml.stream XMLStreamException printStackTrace
public void printStackTrace()
From source file:Main.java
public static int getNextEvent(XMLStreamReader xmlStreamReader) { Integer event = null;/*from w ww. j a v a 2 s. c om*/ try { event = xmlStreamReader.next(); } catch (XMLStreamException e) { e.printStackTrace(); } return event; }
From source file:Main.java
private static XMLStreamReader createXmlStreamReader(XMLInputFactory xmlInputFactory, InputStream inputStream) { XMLStreamReader xmlStreamReader = null; try {/*w w w .ja v a 2 s.c om*/ xmlStreamReader = xmlInputFactory.createXMLStreamReader(inputStream); } catch (XMLStreamException e) { e.printStackTrace(); } return xmlStreamReader; }
From source file:Main.java
public static XMLStreamWriter createStreamWriter() { if (stream != null) { System.out.println("ERROR: there is already an existing stream."); }//from www. jav a2s. c o m stream = new ByteArrayOutputStream(); XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance(); try { XMLStreamWriter writer = xmlFactory.createXMLStreamWriter(stream); writer.writeStartDocument(); return writer; } catch (XMLStreamException e) { e.printStackTrace(); } return null; }
From source file:com.rockhoppertech.music.midi.js.xml.ModeFactoryXMLHelper.java
/** * Read modes.xml and create {@code Scale instances} from those definitions. *//* w w w. j ava2 s.c om*/ public static void init() { List<Integer> intervals = null; Scale currentMode = null; String tagContent = null; XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader = null; try { reader = factory.createXMLStreamReader(ClassLoader.getSystemResourceAsStream("modes.xml")); } catch (XMLStreamException e) { e.printStackTrace(); return; } try { while (reader.hasNext()) { int event = reader.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: String el = reader.getLocalName(); logger.debug("start element '{}'", el); if ("mode".equals(el)) { currentMode = new Scale(); intervals = new ArrayList<>(); } if ("modes".equals(el)) { modeList = new ArrayList<>(); } break; case XMLStreamConstants.CHARACTERS: tagContent = reader.getText().trim(); logger.debug("tagcontent '{}'", tagContent); break; case XMLStreamConstants.END_ELEMENT: switch (reader.getLocalName()) { case "mode": // wow. both guava and commmons to get an int[] array Integer[] array = FluentIterable.from(intervals).toArray(Integer.class); // same as Integer[] array = intervals.toArray(new // Integer[intervals.size()]); int[] a = ArrayUtils.toPrimitive(array); currentMode.setIntervals(a); modeList.add(currentMode); ScaleFactory.registerScale(currentMode); break; case "interval": logger.debug("interval '{}'", tagContent); logger.debug("intervals '{}'", intervals); intervals.add(Integer.parseInt(tagContent)); break; case "name": currentMode.setName(tagContent); break; } break; case XMLStreamConstants.START_DOCUMENT: modeList = new ArrayList<>(); intervals = new ArrayList<>(); break; } } } catch (XMLStreamException e) { logger.error(e.getLocalizedMessage(), e); e.printStackTrace(); } logger.debug("mode list \n{}", modeList); }
From source file:com.hazelcast.simulator.probes.probes.ProbesResultXmlReader.java
public static Map<String, Result> read(InputStream inputStream) { Map<String, Result> result = new HashMap<String, Result>(); XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); try {/*www . j a va2 s . com*/ XMLEventReader reader = xmlInputFactory.createXMLEventReader(inputStream); while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); if (event.isStartElement()) { StartElement startElement = event.asStartElement(); if (PROBES_RESULT.matches(startElement.getName().getLocalPart())) { parseProbesResult(reader, result); } } } } catch (XMLStreamException e) { e.printStackTrace(); } return result; }
From source file:eu.scape_project.planning.xml.ProjectExportAction.java
/** * Dumps binary data to provided file. It results in an XML file with a * single element: data./*from w w w . ja v a2 s.c o m*/ * * @param id * @param data * @param f * @param encoder * @throws IOException */ private static void writeBinaryData(int id, InputStream data, File f) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try { XMLStreamWriter writer = factory.createXMLStreamWriter(new FileWriter(f)); writer.writeStartDocument(PlanXMLConstants.ENCODING, "1.0"); writer.writeStartElement("data"); writer.writeAttribute("id", "" + id); Base64InputStream base64EncodingIn = new Base64InputStream(data, true, PlanXMLConstants.BASE64_LINE_LENGTH, PlanXMLConstants.BASE64_LINE_BREAK); OutputStream out = new WriterOutputStream(new XMLStreamContentWriter(writer), PlanXMLConstants.ENCODING); // read the binary data and encode it on the fly IOUtils.copy(base64EncodingIn, out); out.flush(); // all data is written - end writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); writer.close(); } catch (XMLStreamException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:de.tudarmstadt.ukp.integration.alignment.xml.AlignmentXmlReader.java
public Alignments readAlignments() throws IOException { Alignments alignments = null;/*from w w w . ja va2 s. c om*/ try { XMLEvent e = xmlEventReader.peek(); while (e != null && !isStartElement(e, "alignments")) { xmlEventReader.next(); e = xmlEventReader.peek(); } if (e != null) { alignments = unmarshaller.unmarshal(xmlEventReader, Alignments.class).getValue(); } } catch (XMLStreamException e1) { e1.printStackTrace(); throw new IOException(e1); } catch (JAXBException e1) { e1.printStackTrace(); throw new IOException(e1); } return alignments; }
From source file:com.lin.umws.service.impl.UserServiceImpl.java
public User login(String username, String password) throws UserException { System.out.println("spring: " + springService); HeaderList headerList = (HeaderList) cxt.getMessageContext() .get(JAXWSProperties.INBOUND_HEADER_LIST_PROPERTY); Header header = headerList.get(new QName("http://service.umws.lin.com/", "licenseType"), true); try {/* w ww.j a v a 2 s . c o m*/ XMLStreamReader reader = header.readHeader(); while (reader.hasNext()) { int type = reader.next(); if (type == XMLStreamReader.CHARACTERS) { System.out.println(reader.getText()); } } } catch (XMLStreamException e) { e.printStackTrace(); } for (User user : userMap.values()) { if (username.equals(user.getUsername()) && password.equals(user.getPassword())) { return user; } } throw new UserException("?"); }
From source file:com.tamingtext.tagrecommender.ExtractStackOverflowData.java
public void extract() { XMLInputFactory xif = XMLInputFactory.newInstance(); XMLStreamReader reader = null; InputStream is = null;/*from w w w . j ava 2 s.co m*/ XMLOutputFactory xof = XMLOutputFactory.newInstance(); XMLStreamWriter writer = null; OutputStream os = null; try { log.info("Reading data from " + inputFile); is = new FileInputStream(inputFile); reader = xif.createXMLStreamReader(is); os = new FileOutputStream(trainingOutputFile); writer = xof.createXMLStreamWriter(os); int trainingDataCount = extractXMLData(reader, writer, trainingDataSize); os.close(); os = new FileOutputStream(testOutputFile); writer = xof.createXMLStreamWriter(os); int testDataCount = extractXMLData(reader, writer, testDataSize); os.close(); log.info("Extracted " + trainingDataCount + " rows of training data"); log.info("Extracted " + testDataCount + " rows of test data"); } catch (XMLStreamException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:edu.harvard.i2b2.crc.dao.setfinder.querybuilder.temporal.TemporalPanelCellQueryItem.java
public ProjectType callCellUrlWithRequest() throws Exception { RequestMessageType requestMessageType = getI2B2RequestMessage(parent.getRequestorSecurityType(), parent.getProjectId());/* w w w .j ava 2 s. c o m*/ OMElement requestElement = null; ProjectType projectType = null; try { String requestXmlString = createRequestXmlString(); requestElement = buildOMElement(requestMessageType, requestXmlString); log.debug("call cell request xml " + requestElement); String response = ServiceClient.sendREST(cellUrl, requestElement); log.debug("Got Response"); PatientSet pSet = getPatientSetFromResponseXML(response); if (pSet != null) { StringBuffer patientList = new StringBuffer(); patientList.append("("); boolean first = true; for (PatientType patient : pSet.getPatient()) { if (!first) { patientList.append(", "); } else first = false; if (patient.getPatientId() != null && patient.getPatientId().getValue() != null) patientList.append(patient.getPatientId().getValue()); } patientList.append(")"); patientNums = patientList.toString(); } } catch (XMLStreamException e) { e.printStackTrace(); throw new I2B2Exception("" + StackTraceUtil.getStackTrace(e)); } catch (Exception e) { e.printStackTrace(); throw new I2B2Exception("" + StackTraceUtil.getStackTrace(e)); } log.debug("Returning ProjectType"); return projectType; }