com.thoughtworks.xstream.io.StreamException Java Examples

The following examples show how to use com.thoughtworks.xstream.io.StreamException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XStreamMarshaller.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Convert the given XStream exception to an appropriate exception from the
 * {@code org.springframework.oxm} hierarchy.
 * <p>A boolean flag is used to indicate whether this exception occurs during marshalling or
 * unmarshalling, since XStream itself does not make this distinction in its exception hierarchy.
 * @param ex the XStream exception that occurred
 * @param marshalling indicates whether the exception occurs during marshalling ({@code true}),
 * or unmarshalling ({@code false})
 * @return the corresponding {@code XmlMappingException}
 */
protected XmlMappingException convertXStreamException(Exception ex, boolean marshalling) {
	if (ex instanceof StreamException || ex instanceof CannotResolveClassException ||
			ex instanceof ConversionException) {
		if (marshalling) {
			return new MarshallingFailureException("XStream marshalling exception",  ex);
		}
		else {
			return new UnmarshallingFailureException("XStream unmarshalling exception", ex);
		}
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown XStream exception", ex);
	}
}
 
Example #2
Source File: BinaryStreamReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private Token readToken() {
    if (pushback == null) {
        try {
            Token token = tokenFormatter.read(in);
            switch (token.getType()) {
                case Token.TYPE_MAP_ID_TO_VALUE:
                    idRegistry.put(token.getId(), token.getValue());
                    return readToken(); // Next one please.
                default:
                    return token;
            }
        } catch (IOException e) {
            throw new StreamException(e);
        }
    } else {
        Token result = pushback;
        pushback = null;
        return result;
    }
}
 
Example #3
Source File: SaxWriter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void endNode() {
    try {
        this.flushStartTag();

        String tagName = (String) (this.elementStack.remove(0));

        this.contentHandler.endElement("", tagName, tagName);

        this.depth--;
        if (this.depth == 0 && includeEnclosingDocument) {
            this.endDocument(false);
        }
    } catch (SAXException e) {
        throw new StreamException(e);
    }
}
 
Example #4
Source File: Token.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private Token contructToken(byte type) {
    switch (type) {
        case Token.TYPE_START_NODE:
            return new StartNode();
        case Token.TYPE_MAP_ID_TO_VALUE:
            return new MapIdToValue();
        case Token.TYPE_ATTRIBUTE:
            return new Attribute();
        case Token.TYPE_END_NODE:
            return new EndNode();
        case Token.TYPE_VALUE:
            return new Value();
        default:
            throw new StreamException("Unknown token type");
    }
}
 
Example #5
Source File: XStreamMarshaller.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
    * Convert the given XStream exception to an appropriate exception from the
    * {@code org.springframework.oxm} hierarchy.
    * <p>A boolean flag is used to indicate whether this exception occurs during marshalling or
    * unmarshalling, since XStream itself does not make this distinction in its exception hierarchy.
    * @param ex XStream exception that occurred
    * @param marshalling indicates whether the exception occurs during marshalling ({@code true}),
    * or unmarshalling ({@code false})
    * @return the corresponding {@code XmlMappingException}
    */
protected XmlMappingException convertXStreamException(Exception ex, boolean marshalling) {
	if (ex instanceof StreamException || ex instanceof CannotResolveClassException ||
			ex instanceof ConversionException) {
		if (marshalling) {
			return new MarshallingFailureException("XStream marshalling exception",  ex);
		}
		else {
			return new UnmarshallingFailureException("XStream unmarshalling exception", ex);
		}
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown XStream exception", ex);
	}
}
 
Example #6
Source File: StaxReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected int pullNextEvent() {
    try {
        switch(in.next()) {
            case XMLStreamConstants.START_DOCUMENT:
            case XMLStreamConstants.START_ELEMENT:
                return START_NODE;
            case XMLStreamConstants.END_DOCUMENT:
            case XMLStreamConstants.END_ELEMENT:
                return END_NODE;
            case XMLStreamConstants.CHARACTERS:
                return TEXT;
            case XMLStreamConstants.COMMENT:
                return COMMENT;
            default:
                return OTHER;
        }
    } catch (XMLStreamException e) {
        throw new StreamException(e);
    }
}
 
Example #7
Source File: XStreamMarshaller.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Convert the given XStream exception to an appropriate exception from the
 * {@code org.springframework.oxm} hierarchy.
 * <p>A boolean flag is used to indicate whether this exception occurs during marshalling or
 * unmarshalling, since XStream itself does not make this distinction in its exception hierarchy.
 * @param ex the XStream exception that occurred
 * @param marshalling indicates whether the exception occurs during marshalling ({@code true}),
 * or unmarshalling ({@code false})
 * @return the corresponding {@code XmlMappingException}
 */
protected XmlMappingException convertXStreamException(Exception ex, boolean marshalling) {
	if (ex instanceof StreamException || ex instanceof CannotResolveClassException ||
			ex instanceof ConversionException) {
		if (marshalling) {
			return new MarshallingFailureException("XStream marshalling exception",  ex);
		}
		else {
			return new UnmarshallingFailureException("XStream unmarshalling exception", ex);
		}
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown XStream exception", ex);
	}
}
 
Example #8
Source File: StaxWriter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void flush() {
    try {
        out.flush();
    } catch (XMLStreamException e) {
        throw new StreamException(e);
    }
}
 
Example #9
Source File: Dom4JDriver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @since 1.4
 */
public HierarchicalStreamReader createReader(File in) {
    try {
        final Document document = createReader().read(in);
        return new Dom4JReader(document, getNameCoder());
    } catch (DocumentException e) {
        throw new StreamException(e);
    }
}
 
Example #10
Source File: PrettyPrintDriver.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
public HierarchicalStreamWriter createWriter(OutputStream out) {
	try {
		return createWriter(new OutputStreamWriter(out, "UTF-8"));
	} catch (UnsupportedEncodingException e) {
		throw new StreamException(e);
	}
}
 
Example #11
Source File: StaxWriter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Call this method when you're finished with me
 */
public void close() {
    try {
        out.close();
    } catch (XMLStreamException e) {
        throw new StreamException(e);
    }
}
 
Example #12
Source File: Dom4JDriver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @since 1.4
 */
public HierarchicalStreamReader createReader(URL in) {
    try {
        final Document document = createReader().read(in);
        return new Dom4JReader(document, getNameCoder());
    } catch (DocumentException e) {
        throw new StreamException(e);
    }
}
 
Example #13
Source File: StaxWriter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void addAttribute(String name, String value) {
    try {
        out.writeAttribute(encodeAttribute(name), value);
    } catch (XMLStreamException e) {
        throw new StreamException(e);
    }
}
 
Example #14
Source File: StaxWriter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void endNode() {
    try {
        tagDepth-- ;
        out.writeEndElement();
        if (tagDepth == 0 && writeEnclosingDocument) {
            out.writeEndDocument();
        }
    } catch (XMLStreamException e) {
        throw new StreamException(e);
    }
}
 
Example #15
Source File: StaxWriter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void setValue(String text) {
    try {
        out.writeCharacters(text);
    } catch (XMLStreamException e) {
        throw new StreamException(e);
    }
}
 
Example #16
Source File: Dom4JXmlWriter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @since 1.4
 */
public Dom4JXmlWriter(XMLWriter writer, NameCoder nameCoder) {
    super(nameCoder);
    this.writer = writer;
    this.elementStack = new FastStack(16);
    this.attributes = new AttributesImpl();
    try {
        writer.startDocument();
    } catch (SAXException e) {
        throw new StreamException(e);
    }
}
 
Example #17
Source File: Dom4JXmlWriter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void startNode(String name) {
    if (elementStack.size() > 0) {
        try {
            startElement();
        } catch (SAXException e) {
            throw new StreamException(e);
        }
        started = false;
    }
    elementStack.push(encodeNode(name));
    children = false;
}
 
Example #18
Source File: Dom4JXmlWriter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void setValue(String text) {
    char[] value = text.toCharArray();
    if (value.length > 0) {
        try {
            startElement();
            writer.characters(value, 0, value.length);
        } catch (SAXException e) {
            throw new StreamException(e);
        }
        children = true;
    }
}
 
Example #19
Source File: Dom4JXmlWriter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void flush() {
    try {
        writer.flush();
    } catch (IOException e) {
        throw new StreamException(e);
    }
}
 
Example #20
Source File: BinaryStreamWriter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void flush() {
    try {
        out.flush();
    } catch (IOException e) {
        throw new StreamException(e);
    }
}
 
Example #21
Source File: BinaryStreamWriter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void close() {
    try {
        out.close();
    } catch (IOException e) {
        throw new StreamException(e);
    }
}
 
Example #22
Source File: BinaryStreamWriter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void write(Token token) {
    try {
        tokenFormatter.write(out, token);
    } catch (IOException e) {
        throw new StreamException(e);
    }
}
 
Example #23
Source File: BinaryStreamReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void moveDown() {
    depthState.push();
    Token firstToken = readToken();
    switch (firstToken.getType()) {
        case Token.TYPE_START_NODE:
            depthState.setName(idRegistry.get(firstToken.getId()));
            break;
        default:
            throw new StreamException("Expected StartNode");
    }
    while (true) {
        Token nextToken = readToken();
        switch (nextToken.getType()) {
            case Token.TYPE_ATTRIBUTE:
                depthState.addAttribute(idRegistry.get(nextToken.getId()), nextToken.getValue());
                break;
            case Token.TYPE_VALUE:
                depthState.setValue(nextToken.getValue());
                break;
            case Token.TYPE_END_NODE:
                depthState.setHasMoreChildren(false);
                pushBack(nextToken);
                return;
            case Token.TYPE_START_NODE:
                depthState.setHasMoreChildren(true);
                pushBack(nextToken);
                return;
            default:
                throw new StreamException("Unexpected token " + nextToken);
        }
    }
}
 
Example #24
Source File: BinaryStreamReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void close() {
    try {
        in.close();
    } catch (IOException e) {
        throw new StreamException(e);
    }
}
 
Example #25
Source File: BinaryStreamReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public String get(long id) {
    String result = (String) map.get(new Long(id));
    if (result == null) {
        throw new StreamException("Unknown ID : " + id);
    } else {
        return result;
    }
}
 
Example #26
Source File: XMLConfigurationTest.java    From oval with Eclipse Public License 2.0 5 votes vote down vote up
public void testVulnerability_ExternalEntityReferences() {
   final XMLConfigurer x1 = new XMLConfigurer();
   try {
      x1.fromXML(new File("src/test/resources/net/sf/oval/test/validator/XMLConfigurationTest_Vulnerability_ExternalEntityReferences.xml"));
      fail();
   } catch (final StreamException ex) {
      final String msg = ex.getCause().getMessage();
      assertTrue(msg.contains("External Entity: Failed to read external document 'XMLConfigurationTest1.inc.xml', "
         + "because 'file' access is not allowed due to restriction set by the accessExternalDTD property.") || //
         msg.contains("DOCTYPE is disallowed when the feature \"http://apache.org/xml/features/disallow-doctype-decl\" set to true."));
   }
}
 
Example #27
Source File: XMLConfigurationTest.java    From oval with Eclipse Public License 2.0 5 votes vote down vote up
public void testVulnerability_NonXmlFile() {
   final XMLConfigurer x1 = new XMLConfigurer();
   try {
      x1.fromXML(new File("src/test/resources/net/sf/oval/test/validator/XMLConfigurationTest_Vulnerability_NonXmlFile.xml"));
      fail();
   } catch (final StreamException ex) {
      assertTrue(ex.getCause().getMessage().contains("Referencing entity [file:///C:/Windows/System32/drivers/etc/hosts] is not allowed"));
   }
}
 
Example #28
Source File: XMLConfigurationTest.java    From oval with Eclipse Public License 2.0 5 votes vote down vote up
public void testVulnerability_RecursiveInclude() {
   final XMLConfigurer x1 = new XMLConfigurer();
   try {
      x1.fromXML(new File("src/test/resources/net/sf/oval/test/validator/XMLConfigurationTest_Vulnerability_RecursiveInclude.xml"));
      fail();
   } catch (final StreamException ex) {
      assertTrue(ex.getCause().getMessage().contains("Recursive include detected"));
   }
}
 
Example #29
Source File: PrettyPrintDriver.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
public HierarchicalStreamReader createReader(InputStream in) {
	try {
		return createReader(new InputStreamReader(in, "UTF-8"));
	} catch (UnsupportedEncodingException e) {
		throw new StreamException(e);
	}
}
 
Example #30
Source File: XppReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void close() {
    try {
        reader.close();
    } catch (IOException e) {
        throw new StreamException(e);
    }
}