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

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

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

XDIReader.read介绍

[英]Reads an XDI graph from a byte stream.
[中]从字节流读取XDI图形。

代码示例

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

@Override
public void load(MemoryGraph memoryGraph) {
  memoryGraph.clear();
  try {
    File file = new File(this.path);
    if (! file.exists()) {
      if (log.isDebugEnabled()) log.debug("File " + file.getAbsolutePath() + " does not exist. Not loading.");
      return;
    }
    if (log.isDebugEnabled()) log.debug("Loading file " + file.getAbsolutePath());
    Reader reader = new FileReader(file);
    this.xdiReader.read(memoryGraph, reader);
    reader.close();
  } catch (Exception ex) {
    throw new Xdi2RuntimeException("Cannot load file at " + this.path, ex);
  }
}

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

@Override
  public Graph parseGraph(String string, MimeType mimeType) throws IOException, Xdi2ParseException {

    Graph graph = this.openGraph();
    XDIReaderRegistry.forMimeType(mimeType).read(graph, new StringReader(string));

    return graph;
  }
}

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

@Override
public Graph parseGraph(String string, String format, Properties parameters) throws IOException, Xdi2ParseException {
  Graph graph = this.openGraph();
  XDIReaderRegistry.forFormat(format, parameters).read(graph, new StringReader(string));
  return graph;
}

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

private synchronized void read(Graph graph, byte[] byteArray) throws Xdi2ParseException {
  for (XDIReader xdiReader : readers) {
    if (xdiReader instanceof AutoReader) continue;
    try {
      graph.clear();
      xdiReader.read(graph, new ByteArrayInputStream(byteArray));
      this.lastSuccessfulReader = xdiReader;
      return;
    } catch(Exception ex) {
      continue;
    }
  }
  this.lastSuccessfulReader = null;
  throw new Xdi2ParseException("Unknown serialization format.");
}

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

private synchronized void read(Graph graph, String string) throws Xdi2ParseException {
  for (XDIReader xdiReader : readers) {
    if (xdiReader instanceof AutoReader) continue;
    try {
      graph.clear();
      xdiReader.read(graph, new StringReader(string));
      this.lastSuccessfulReader = xdiReader;
      return;
    } catch(Exception ex) {
      continue;
    }
  }
  this.lastSuccessfulReader = null;
  throw new Xdi2ParseException("Unknown serialization format.");
}

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

@Override
public void load(MemoryGraph memoryGraph) {
  memoryGraph.clear();
  String classpath = this.getClasspath();
  if (classpath.startsWith("/")) classpath = classpath.substring(1);
  try {
    if (log.isDebugEnabled()) log.debug("Loading classpath " + classpath);
    InputStream stream = this.getClassLoader().getResourceAsStream(classpath);
    this.xdiReader.read(memoryGraph, stream);
    stream.close();
  } catch (Exception ex) {
    throw new Xdi2RuntimeException("Cannot load classpath at " + classpath + " with classloader " + this.getClassLoader().getClass().getCanonicalName(), ex);
  }
}

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

@Override
public void load(MemoryGraph memoryGraph) {
  memoryGraph.clear();
  try {
    if (log.isDebugEnabled()) log.debug("Loading URL " + this.getUrl());
    InputStream stream = this.getUrl().openStream();
    this.xdiReader.read(memoryGraph, stream);
    stream.close();
  } catch (Exception ex) {
    throw new Xdi2RuntimeException("Cannot load URL at " + this.getUrl(), ex);
  }
}

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

xdiReader.read(graph, reader);
} catch (IOException ex) {

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

private static MessageEnvelope readFromBody(HttpTransportRequest request, HttpTransportResponse response) throws IOException {
  InputStream inputStream = request.getBodyInputStream();
  // try to find an appropriate reader for the provided mime type
  XDIReader xdiReader = null;
  String contentType = request.getContentType();
  MimeType recvMimeType = contentType != null ? new MimeType(contentType) : null;
  xdiReader = recvMimeType != null ? XDIReaderRegistry.forMimeType(recvMimeType) : null;
  if (xdiReader == null) xdiReader = XDIReaderRegistry.getDefault();
  // read everything into an in-memory XDI graph (a message envelope)
  if (log.isDebugEnabled()) log.debug("Reading message in " + recvMimeType + " with reader " + xdiReader.getClass().getSimpleName() + ".");
  MessageEnvelope messageEnvelope;
  try {
    Graph graph = MemoryGraphFactory.getInstance().openGraph();
    xdiReader.read(graph, inputStream);
    messageEnvelope = MessageEnvelope.fromGraph(graph);
  } catch (IOException ex) {
    throw ex;
  } catch (Exception ex) {
    log.error("Cannot parse XDI graph: " + ex.getMessage(), ex);
    throw new IOException("Cannot parse XDI graph: " + ex.getMessage(), ex);
  } finally {
    inputStream.close();
  }
  if (log.isDebugEnabled()) log.debug("Message envelope received (" + messageEnvelope.getMessageCount() + " messages). Executing...");
  // done
  return messageEnvelope;
}

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

private static MessageEnvelope read(WebSocketTransportRequest request, WebSocketTransportResponse response) throws IOException {
  Reader reader = request.getReader();
  // try to find an appropriate reader for the provided mime type
  XDIReader xdiReader = null;
  String contentType = request.getNegotiatedSubprotocol();
  MimeType recvMimeType = contentType != null ? new MimeType(contentType) : null;
  xdiReader = recvMimeType != null ? XDIReaderRegistry.forMimeType(recvMimeType) : null;
  if (xdiReader == null) xdiReader = XDIReaderRegistry.getDefault();
  // read everything into an in-memory XDI graph (a message envelope)
  if (log.isDebugEnabled()) log.debug("Reading message in " + recvMimeType + " with reader " + xdiReader.getClass().getSimpleName() + ".");
  MessageEnvelope messageEnvelope;
  try {
    Graph graph = MemoryGraphFactory.getInstance().openGraph();
    xdiReader.read(graph, reader);
    messageEnvelope = MessageEnvelope.fromGraph(graph);
  } catch (IOException ex) {
    throw ex;
  } catch (Exception ex) {
    log.error("Cannot parse XDI graph: " + ex.getMessage(), ex);
    throw new IOException("Cannot parse XDI graph: " + ex.getMessage(), ex);
  } finally {
    reader.close();
  }
  if (log.isDebugEnabled()) log.debug("Message envelope received (" + messageEnvelope.getMessageCount() + " messages). Executing...");
  // done
  return messageEnvelope;
}

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

/**
 * Returns the graph from a normalized string.
 */
public static Graph deserialize(String string) throws Xdi2ParseException, IOException {
  Graph tempGraph = MemoryGraphFactory.getInstance().openGraph();
  try {
    XDIREADER.read(tempGraph, new StringReader(string));
  } catch (Xdi2ParseException ex) {
    tempGraph.close();
    throw ex;
  } catch (IOException ex) {
    tempGraph.close();
    throw ex;
  }
  return tempGraph;
}

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

private void readGraph(ExecutionContext executionContext) throws Xdi2MessagingException {
  XDIReader xdiReader = XDIReaderRegistry.forFormat(this.mimeType, null);
  if (xdiReader == null) throw new Xdi2MessagingException("Cannot read this format: " + this.mimeType, null, executionContext);
  Graph graph = this.getGraph();
  graph.clear();
  FileReader reader = null;
  try {
    File file = new File(this.path);
    reader = new FileReader(file);
    xdiReader.read(graph, reader);
    reader.close();
  } catch (FileNotFoundException ex) {
  } catch (Exception ex) {
    throw new Xdi2MessagingException("Cannot read file: " + ex.getMessage(), ex, executionContext);
  } finally {
    if (reader != null) {
      try {
        reader.close();
      } catch (Exception ex) { }
    }
  }
  if (xdiReader instanceof AutoReader) this.mimeType = ((AutoReader) xdiReader).getLastSuccessfulReader().getFormat();
  if (this.mimeType == null) this.mimeType = XDIWriterRegistry.getDefault().getFormat();
}

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

reader.read(messagingResponseGraph, inputStream);
  inputStream.close();
} catch (Exception ex) {

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

xdiReader.read(graph, new StringReader(graphstring));
} catch (Xdi2ParseException ex) {
  xdiReader.read(messageEnvelope.getGraph(), new StringReader(graphstring));

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

public void testReadJson() throws Exception {
  Graph graph3 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-3");
  XDIReader reader = XDIReaderRegistry.forFormat("XDI/JSON", null);
  reader.read(graph3, AbstractGraphTest.class.getResourceAsStream("test.json")).close();
  testGraph(graph3);
  graph3.getRootContextNode().clear();
  assertTrue(graph3.isEmpty());
  graph3.close();
}

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

public void testReadWriteFormats() throws Exception {
  String[] formats = new String[] { "XDI/JSON", "XDI DISPLAY" };
  for (int i=0; i<formats.length; i++) {
    File file = new File("xdi.out");
    Graph graph4 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-4" + "-" + i);
    Graph graph5 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-5" + "-" + i);
    XDIWriter writer = XDIWriterRegistry.forFormat(formats[i], null);
    XDIReader reader = XDIReaderRegistry.forFormat(formats[i], null);
    FileWriter fileWriter = new FileWriter(file);
    FileReader fileReader = new FileReader(file);
    makeGraph(graph4);
    writer.write(graph4, fileWriter);
    reader.read(graph5, fileReader);
    fileWriter.close();
    fileReader.close();
    testGraph(graph5);
    testGraphsEqual(graph4, graph5);
    graph4.close();
    graph5.close();
    file.delete();
  }
}

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

autoReader.read(graph, this.getClass().getResourceAsStream("graph" + i + ".xdi")).close();
    autoReader.read(message, this.getClass().getResourceAsStream("message" + i + "." + ii + ".xdi")).close();
    autoReader.read(positive, this.getClass().getResourceAsStream("positive" + i + "." + ii + ".xdi")).close();
    autoReader.read(negative, this.getClass().getResourceAsStream("negative" + i + "." + ii + ".xdi")).close();
    autoReader.read(exception, this.getClass().getResourceAsStream("exception" + i + "." + ii + ".xdi")).close();

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

autoReader.read(graph, this.getClass().getResourceAsStream("graph" + i + ".xdi")).close();
  autoReader.read(authorized, this.getClass().getResourceAsStream("authorized" + i + "." + ii + ".xdi")).close();
  autoReader.read(notauthorized, this.getClass().getResourceAsStream("notauthorized" + i + "." + ii + ".xdi")).close();

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

graph10.clear();
graph11.clear();
XDIReaderRegistry.forFormat("XDI/JSON", null).read(graph10, new StringReader(buffer1.toString()));
XDIReaderRegistry.forFormat("XDI DISPLAY", null).read(graph11, new StringReader(buffer2.toString()));

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

XDIReaderRegistry.forMimeType(mimeTypes[i]).read(graph1a, new StringReader(graph1.toString(mimeTypes[i])));
XDIReaderRegistry.forMimeType(mimeTypes[ii]).read(graph2a, new StringReader(graph2.toString(mimeTypes[ii])));

相关文章

XDIReader类方法