xdi2.core.io.XDIWriterRegistry.forFormat()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(4.1k)|赞(0)|评价(0)|浏览(137)

本文整理了Java中xdi2.core.io.XDIWriterRegistry.forFormat()方法的一些代码示例,展示了XDIWriterRegistry.forFormat()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XDIWriterRegistry.forFormat()方法的具体详情如下:
包路径:xdi2.core.io.XDIWriterRegistry
类名称:XDIWriterRegistry
方法名:forFormat

XDIWriterRegistry.forFormat介绍

[英]Returns an XDIWriter for the specified format, e.g.

  • XDI/JSON
  • XDI DISPLAY
    [中]返回指定格式的XDIWriter,例如。
    *XDI/JSON
    *XDI显示器

代码示例

代码示例来源:origin: projectdanube/xdi2

  1. @Override
  2. public String toString(String format, Properties parameters) {
  3. if (format == null) format = XDIWriterRegistry.getDefault().getFormat();
  4. XDIWriter writer = XDIWriterRegistry.forFormat(format, parameters);
  5. if (writer == null) throw new Xdi2RuntimeException("Unknown format for XDI serialization: " + format);
  6. StringWriter buffer = new StringWriter();
  7. try {
  8. writer.write(this, buffer);
  9. } catch (IOException ex) {
  10. return "[Exception: " + ex.getMessage() + "]";
  11. }
  12. return buffer.toString();
  13. }

代码示例来源:origin: projectdanube/xdi2

  1. private void writeGraph(ExecutionContext executionContext) throws Xdi2MessagingException {
  2. XDIWriter xdiWriter = XDIWriterRegistry.forFormat(this.mimeType, null);
  3. if (xdiWriter == null) throw new Xdi2MessagingException("Cannot write this format: " + this.mimeType, null, executionContext);
  4. Graph graph = this.getGraph();
  5. FileWriter writer = null;
  6. try {
  7. File file = new File(this.path);
  8. file.createNewFile();
  9. writer = new FileWriter(file);
  10. xdiWriter.write(graph, writer);
  11. writer.close();
  12. } catch (Exception ex) {
  13. throw new Xdi2MessagingException("Cannot write file: " + ex.getMessage(), ex, executionContext);
  14. } finally {
  15. if (writer != null) try { writer.close(); } catch (Exception ex) { }
  16. }
  17. graph.close();
  18. }

代码示例来源:origin: projectdanube/xdi2

  1. XDIWriter xdiWriter = XDIWriterRegistry.forFormat(format, xdiWriterParameters);
  2. StringWriter xdiStringWriter = new StringWriter();
  3. xdiWriter.write(graph, xdiStringWriter);
  4. XDIWriter xdiWriter = XDIWriterRegistry.forFormat(format, xdiWriterParameters);
  5. StringWriter xdiStringWriter = new StringWriter();
  6. xdiWriter.write(graph, xdiStringWriter);
  7. XDIWriter xdiWriter = XDIWriterRegistry.forFormat(format, xdiWriterParameters);
  8. StringWriter stringWriter = new StringWriter();
  9. xdiWriter.write(resultGraph, stringWriter);

代码示例来源:origin: projectdanube/xdi2

  1. public void testReadWriteFormats() throws Exception {
  2. String[] formats = new String[] { "XDI/JSON", "XDI DISPLAY" };
  3. for (int i=0; i<formats.length; i++) {
  4. File file = new File("xdi.out");
  5. Graph graph4 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-4" + "-" + i);
  6. Graph graph5 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-5" + "-" + i);
  7. XDIWriter writer = XDIWriterRegistry.forFormat(formats[i], null);
  8. XDIReader reader = XDIReaderRegistry.forFormat(formats[i], null);
  9. FileWriter fileWriter = new FileWriter(file);
  10. FileReader fileReader = new FileReader(file);
  11. makeGraph(graph4);
  12. writer.write(graph4, fileWriter);
  13. reader.read(graph5, fileReader);
  14. fileWriter.close();
  15. fileReader.close();
  16. testGraph(graph5);
  17. testGraphsEqual(graph4, graph5);
  18. graph4.close();
  19. graph5.close();
  20. file.delete();
  21. }
  22. }

代码示例来源:origin: projectdanube/xdi2

  1. XDIWriterRegistry.forFormat("XDI/JSON", null).write(graph10, buffer1);
  2. XDIWriterRegistry.forFormat("XDI DISPLAY", null).write(graph11, buffer2);
  3. graph10.clear();
  4. graph11.clear();

代码示例来源:origin: projectdanube/xdi2

  1. public void testWriters() throws Exception {
  2. String[] formats = new String[] { "XDI/JSON", "XDI DISPLAY", "KEYVALUE" };
  3. String[] fileExtensions = new String[] { "json", "xdi" };
  4. MimeType[] mimeTypes = new MimeType[] { new MimeType("application/xdi+json"), new MimeType("application/xdi+json;contexts=0"), new MimeType("application/xdi+json;contexts=1"), new MimeType("text/xdi"), new MimeType("text/xdi;contexts=0"), new MimeType("text/xdi;contexts=1") };
  5. for (String format : formats) assertTrue(XDIWriterRegistry.forFormat(format, null).supportsFormat(format));
  6. for (String fileExtension : fileExtensions) assertTrue(XDIWriterRegistry.forFileExtension(fileExtension, null).supportsFileExtension(fileExtension));
  7. for (MimeType mimeType : mimeTypes) assertTrue(XDIWriterRegistry.forMimeType(mimeType).supportsMimeType(mimeType));
  8. }
  9. }

相关文章