use of org.apache.openejb.util.LengthInputStream in project tomee by apache.
the class ReadDescriptors method isEmpty.
private static boolean isEmpty(final InputStream is, final String rootElement) throws IOException, ParserConfigurationException, SAXException {
final LengthInputStream in = new LengthInputStream(is);
final InputSource inputSource = new InputSource(in);
final SAXParser parser;
final Thread thread = Thread.currentThread();
final ClassLoader original = thread.getContextClassLoader();
thread.setContextClassLoader(Saxs.class.getClassLoader());
try {
parser = Saxs.namespaceAwareFactory().newSAXParser();
} finally {
thread.setContextClassLoader(original);
}
try {
parser.parse(inputSource, new DefaultHandler() {
public void startElement(final String uri, final String localName, final String qName, final Attributes att) throws SAXException {
if (!localName.equals(rootElement)) {
throw new SAXException(localName);
}
}
public InputSource resolveEntity(final String publicId, final String systemId) throws IOException, SAXException {
return new InputSource(new ByteArrayInputStream(new byte[0]));
}
});
return true;
} catch (final SAXException e) {
return in.getLength() == 0;
}
}
use of org.apache.openejb.util.LengthInputStream in project tomee by apache.
the class ReadDescriptors method getId.
private static String getId(final InputStream is) {
final String[] id = { null };
try {
final LengthInputStream in = new LengthInputStream(is);
final InputSource inputSource = new InputSource(in);
final SAXParser parser = Saxs.namespaceAwareFactory().newSAXParser();
parser.parse(inputSource, new DefaultHandler() {
public void startElement(final String uri, final String localName, final String qName, final Attributes att) throws SAXException {
id[0] = att.getValue("id");
}
public InputSource resolveEntity(final String publicId, final String systemId) throws IOException, SAXException {
return new InputSource(new ByteArrayInputStream(new byte[0]));
}
});
} catch (final Exception e) {
// no-op
}
return id[0];
}
Aggregations