当前位置: 首页>>代码示例>>Java>>正文


Java XStreamException类代码示例

本文整理汇总了Java中com.thoughtworks.xstream.XStreamException的典型用法代码示例。如果您正苦于以下问题:Java XStreamException类的具体用法?Java XStreamException怎么用?Java XStreamException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


XStreamException类属于com.thoughtworks.xstream包,在下文中一共展示了XStreamException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initialize

import com.thoughtworks.xstream.XStreamException; //导入依赖的package包/类
/**
 * Initialize the population by either reading it from the file or making a new one from scratch
 * 
 * @param space
 */
@Override
public void initialize(Toroidal2DPhysics space) {
	XStream xstream = new XStream();
	xstream.alias("ExampleGAPopulation", ExampleGAPopulation.class);

	// try to load the population from the existing saved file.  If that failes, start from scratch
	try { 
		population = (ExampleGAPopulation) xstream.fromXML(new File(getKnowledgeFile()));
	} catch (XStreamException e) {
		// if you get an error, handle it other than a null pointer because
		// the error will happen the first time you run
		System.out.println("No existing population found - starting a new one from scratch");
		population = new ExampleGAPopulation(populationSize);
	}

	currentPolicy = population.getFirstMember();
}
 
开发者ID:amymcgovern,项目名称:spacesettlers,代码行数:23,代码来源:ExampleGAClient.java

示例2: initialize

import com.thoughtworks.xstream.XStreamException; //导入依赖的package包/类
/**
 * Demonstrates one way to read in knowledge from a file
 */
@Override
public void initialize(Toroidal2DPhysics space) {
	asteroidToShipMap = new HashMap<UUID, Ship>();
	aimingForBase = new HashMap<UUID, Boolean>();
	
	XStream xstream = new XStream();
	xstream.alias("ExampleKnowledge", ExampleKnowledge.class);

	try { 
		myKnowledge = (ExampleKnowledge) xstream.fromXML(new File(knowledgeFile));
	} catch (XStreamException e) {
		// if you get an error, handle it other than a null pointer because
		// the error will happen the first time you run
		myKnowledge = new ExampleKnowledge();
	}
}
 
开发者ID:amymcgovern,项目名称:spacesettlers,代码行数:20,代码来源:PacifistHeuristicAsteroidCollectorTeamClient.java

示例3: load

import com.thoughtworks.xstream.XStreamException; //导入依赖的package包/类
/**
 * Optionally (if the deserialization is successful) loads a <code>History</code> from the given
 * <code>InputStream</code>.
 *
 * @param stream
 *         the <code>InputStream</code> to load the <code>History</code> from
 * @return optionally the loaded <code>History</code>
 */
public static Optional<History> load(InputStream stream) {
    History history;

    try {
        history = (History) serializer.fromXML(stream);
        history.history.stream().filter(state -> GUI.isDumpGraph(state.getCmdArgs())).forEach(state -> {
            GraphvizParser p = new GraphvizParser(state.getOutput());
            state.setTreeViewTabs(p.call().stream().map(GUI::getTreeTableViewTab).collect(Collectors.toList()));
        });
    } catch (XStreamException | ClassCastException e) {
        LOG.log(Level.WARNING, e, () -> "History deserialization failed.");
        return Optional.empty();
    }

    return Optional.of(history);
}
 
开发者ID:se-passau,项目名称:jdime,代码行数:25,代码来源:History.java

示例4: translateFindAll

import com.thoughtworks.xstream.XStreamException; //导入依赖的package包/类
@Override
public List<ErrorTypeNotificationConfiguration> translateFindAll(
		String returnValue) throws MethodException, RetrievalException {
	int firstLineBreakIndex = returnValue.indexOf("\r\n");
	String firstLine;
	if (firstLineBreakIndex > 0)
		firstLine = returnValue.substring(0, firstLineBreakIndex);
	else
		firstLine = returnValue;
	String[] lineParts = firstLine.split(DELIMITER);
	if (Integer.parseInt(lineParts[0]) == -1)
		throw new MethodException(returnValue);
	String messageContent = returnValue.substring(firstLineBreakIndex + 2);
	ErrorTypeNotificationConfigurationContainer container;
	try {
		XStream deserializer = getConfiguredXStream();
		container = (ErrorTypeNotificationConfigurationContainer) deserializer.fromXML(messageContent);
	} catch (XStreamException xsX) {
		throw new MethodException(xsX.getMessage(), xsX);
	}
	return container.getConfigs();
}
 
开发者ID:VHAINNOVATIONS,项目名称:Telepathology,代码行数:23,代码来源:ErrorTypeNotificationConfigurationDAO.java

示例5: translateServiceRegistrations

import com.thoughtworks.xstream.XStreamException; //导入依赖的package包/类
public List<ServiceRegistration> translateServiceRegistrations(
		String message) throws MethodException, ConnectionException {
	int firstLineBreakIndex = message.indexOf("\r\n");
	String firstLine;
	if (firstLineBreakIndex > 0)
		firstLine = message.substring(0, firstLineBreakIndex);
	else
		firstLine = message;
	String[] lineParts = firstLine.split(DELIMITER);
	if (Integer.parseInt(lineParts[0]) == -1)
		throw new MethodException(message);
	String messageContent = message.substring(firstLineBreakIndex + 2);
	ServiceRegistry registry;
	try {
		XStream deserializer = getConfiguredXStream();
		registry = (ServiceRegistry) deserializer.fromXML(messageContent);
	} catch (XStreamException xsX) {
		throw new MethodException(xsX.getMessage(), xsX);
	}
	return registry.getRegistrations();
}
 
开发者ID:VHAINNOVATIONS,项目名称:Telepathology,代码行数:22,代码来源:ServiceRegistrationDAO.java

示例6: testCannotInjectEventHandler

import com.thoughtworks.xstream.XStreamException; //导入依赖的package包/类
public void testCannotInjectEventHandler() {
    final String xml = ""
        + "<string class='runnable-array'>\n"
        + "  <dynamic-proxy>\n"
        + "    <interface>java.lang.Runnable</interface>\n"
        + "    <handler class='java.beans.EventHandler'>\n"
        + "      <target class='com.thoughtworks.acceptance.SecurityVulnerabilityTest$Exec'/>\n"
        + "      <action>exec</action>\n"
        + "    </handler>\n"
        + "  </dynamic-proxy>\n"
        + "</string>";

    try {
        xstream.fromXML(xml);
        fail("Thrown " + XStreamException.class.getName() + " expected");
    } catch (final XStreamException e) {
        assertTrue(e.getMessage().contains(EventHandler.class.getName()));
    }
    assertEquals(0, BUFFER.length());
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:21,代码来源:SecurityVulnerabilityTest.java

示例7: testCausingExceptionIsNotSuppressed

import com.thoughtworks.xstream.XStreamException; //导入依赖的package包/类
public void testCausingExceptionIsNotSuppressed() {
    try {
        toXML(new InvalidForConverter());
        fail("Thrown " + XStreamException.class.getName() + " expected");
    } catch (final XStreamException e) {
        Throwable th = e.getCause();
        for(;;) {
            th = th.getCause();
            assertNotNull("No causing InitializationException.", th);
            if (th instanceof InitializationException) {
                assertTrue("No hint for enum types only", th.getMessage().indexOf(" enum ") >= 0);
                break;
            }
        }
    }
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:17,代码来源:FieldConverterTest.java

示例8: testIsXXEVulnerableWithExternalParameterEntity

import com.thoughtworks.xstream.XStreamException; //导入依赖的package包/类
@Override
public void testIsXXEVulnerableWithExternalParameterEntity() throws Exception {
    try {
        super.testIsXXEVulnerableWithExternalParameterEntity();
        fail("Thrown " + XStreamException.class.getName() + " expected");
    } catch (final XStreamException e) {
        final String message = e.getCause().getMessage();
        if (!message.contains("external entity")) {
            if (message.contains("com.wutka.dtd.DTDParseException")) {
                System.err.println("BEAStaxReader was selected as default StAX driver for StaxReaderTest!");
            } else {
                throw e;
            }
        }
    }
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:17,代码来源:StaxReaderTest.java

示例9: realClass

import com.thoughtworks.xstream.XStreamException; //导入依赖的package包/类
public Class realClass(String paramString)
{
  Object localObject = this.realClassCache.get(paramString);
  if (localObject != null)
  {
    if ((localObject instanceof Class))
      return (Class)localObject;
    throw ((XStreamException)localObject);
  }
  try
  {
    Class localClass = super.realClass(paramString);
    this.realClassCache.put(paramString, localClass);
    return localClass;
  }
  catch (ForbiddenClassException localForbiddenClassException)
  {
    this.realClassCache.put(paramString, localForbiddenClassException);
    throw localForbiddenClassException;
  }
  catch (CannotResolveClassException localCannotResolveClassException)
  {
    this.realClassCache.put(paramString, localCannotResolveClassException);
    throw localCannotResolveClassException;
  }
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:27,代码来源:CachingMapper.java

示例10: writeToFile

import com.thoughtworks.xstream.XStreamException; //导入依赖的package包/类
/**
 * Write an object to a file. The default implementation uses XStream.
 * Override to use another way to write objects. Must be compatible with the
 * {@link #readFromFile(Path)} method
 * 
 * @param path
 *            the path of the file to be written
 * @param object
 *            the object to be written
 * @throws IOException
 *             if the object can not be write to the file
 */
protected void writeToFile(Path path, Object object) throws IOException {
    XStream xstream = createXStream();

    OutputStream outputStream;

    // TODO output to temp file and then copy

    outputStream = Files.newOutputStream(path);

    try {
        xstream.toXML(object, outputStream);
    } catch (XStreamException e) {
        throw new IOException(e);
    }
}
 
开发者ID:corehunter,项目名称:corehunter3,代码行数:28,代码来源:FileBasedDatasetServices.java

示例11: readFromFile

import com.thoughtworks.xstream.XStreamException; //导入依赖的package包/类
/**
 * Reads an object from a file. The default implementation uses XStream.
 * Override to use another way to read objects. Must be compatible with the
 * {@link #writeToFile(Path, Object)} method
 * 
 * @param path
 *            the path of the file to be read
 * @return the object read from the file
 * @throws IOException
 *             if the object can not be read from the file
 */
protected Object readFromFile(Path path) throws IOException {
    XStream xstream = createXStream();

    InputStream inputStream = Files.newInputStream(path);

    // TODO output to temp file and then copy

    try {
        return xstream.fromXML(inputStream);
    } catch (XStreamException e) {
        e.printStackTrace();

        throw new IOException(e);
    }
}
 
开发者ID:corehunter,项目名称:corehunter3,代码行数:27,代码来源:SimpleCoreHunterRunServices.java

示例12: writeToFile

import com.thoughtworks.xstream.XStreamException; //导入依赖的package包/类
/**
 * Write an object to a file. The default implementation uses XStream.
 * Override to use another way to write objects. Must be compatible with the
 * {@link #readFromFile(Path)} method
 * 
 * @param path
 *            the path of the file to be written
 * @param object
 *            the object to be written
 * @throws IOException
 *             if the object can not be write to the file
 */
protected void writeToFile(Path path, Object object) throws IOException {
    XStream xstream = createXStream();

    OutputStream outputStream;

    // TODO output to temp file and then copy

    outputStream = Files.newOutputStream(path);

    try {
        xstream.marshal(object, new PrettyPrintWriter(new OutputStreamWriter(outputStream)));
    } catch (XStreamException e) {
        throw new IOException(e);
    }
}
 
开发者ID:corehunter,项目名称:corehunter3,代码行数:28,代码来源:SimpleCoreHunterRunServices.java

示例13: toXML

import com.thoughtworks.xstream.XStreamException; //导入依赖的package包/类
/**
 * Convert an object to XML
 * 
 * @param obj
 * @return XML string representation
 */
public static String toXML(Object obj)
{
	init();
	if (xs != null)
	{
		try
		{
			return xs.toXML(obj);
		}
		catch (XStreamException ex)
		{
			//ex.printStackTrace();
		}
	}
	return "";
}
 
开发者ID:aherbert,项目名称:GDSC-SMLM,代码行数:23,代码来源:XmlUtils.java

示例14: fromXML

import com.thoughtworks.xstream.XStreamException; //导入依赖的package包/类
/**
 * Load an object from the XML string representation
 * 
 * @param xml
 * @return the object
 */
public static Object fromXML(String xml)
{
	init();
	if (xs != null)
	{
		try
		{
			return xs.fromXML(xml);
		}
		catch (XStreamException ex)
		{
			//ex.printStackTrace();
		}
	}
	return null;
}
 
开发者ID:aherbert,项目名称:GDSC-SMLM,代码行数:23,代码来源:XmlUtils.java

示例15: readDictionary

import com.thoughtworks.xstream.XStreamException; //导入依赖的package包/类
/**
 * Reads a dictionary from the provided reader.
 * @param reader reader, cannot be null
 * @return the corresponding dictionary
 * @throws IOException if the dictionary could not be read
 */
public static NaaccrDictionary readDictionary(Reader reader) throws IOException {
    try {
        NaaccrDictionary dictionary = (NaaccrDictionary)instanciateXStream().fromXML(reader);

        if (dictionary.getSpecificationVersion() == null)
            dictionary.setSpecificationVersion(SpecificationVersion.SPEC_1_0);

        // let's not validate the internal dictionaries, we know they are valid
        String uri = dictionary.getDictionaryUri();
        if (uri == null || uri.trim().isEmpty())
            throw new IOException("'dictionaryUri' attribute is required");
        else if (!BASE_DICTIONARY_URI_PATTERN.matcher(uri).matches() && !DEFAULT_USER_DICTIONARY_URI_PATTERN.matcher(uri).matches()) {
            String error = validateUserDictionary(dictionary);
            if (error != null)
                throw new IOException(error);
        }

        return dictionary;
    }
    catch (XStreamException ex) {
        throw new IOException("Unable to read dictionary", ex);
    }
}
 
开发者ID:imsweb,项目名称:naaccr-xml,代码行数:30,代码来源:NaaccrXmlDictionaryUtils.java


注:本文中的com.thoughtworks.xstream.XStreamException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。