gpt4 book ai didi

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

转载 作者:知者 更新时间:2024-03-26 08:53:05 25 4
gpt4 key购买 nike

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

XDIReaderRegistry.forMimeType介绍

[英]Returns an XDIReader for the specified mime type, e.g.

  • application/xdi+json
  • text/xdi
    [中]返回指定mime类型的XDIReader,例如。
    *application/xdi+json
    *文本/xdi

代码示例

代码示例来源: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

xdiReader = recvMimeType != null ? XDIReaderRegistry.forMimeType(recvMimeType) : null;

代码示例来源: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

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

@Override
public WrapperStore openWrapper(String identifier) throws IOException {
  // initialize graph
  XDIReader xdiReader = XDIReaderRegistry.forMimeType(this.mimeType == null ? null : new MimeType(this.mimeType));
  XDIWriter xdiWriter = XDIWriterRegistry.forMimeType(this.mimeType == null ? null : new MimeType(this.mimeType));
  return new URLWrapperStore(this.url, this.mimeType, xdiReader, xdiWriter);
}

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

@Override
public WrapperStore openWrapper(String identifier) throws IOException {
  // initialize graph
  XDIReader xdiReader = XDIReaderRegistry.forMimeType(this.mimeType == null ? null : new MimeType(this.mimeType));
  XDIWriter xdiWriter = XDIWriterRegistry.forMimeType(this.mimeType == null ? null : new MimeType(this.mimeType));
  return new ClasspathWrapperStore(this.classpath, this.mimeType, xdiReader, xdiWriter);
}

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

@Override
public WrapperStore openWrapper(String identifier) throws IOException {
  // check identifier
  String path = this.getPath();
  if (path == null) {
    path = FILE_PREFIX + identifier + FILE_SUFFIX;
  }
  // initialize graph
  XDIReader xdiReader = XDIReaderRegistry.forMimeType(this.mimeType == null ? null : new MimeType(this.mimeType));
  XDIWriter xdiWriter = XDIWriterRegistry.forMimeType(this.mimeType == null ? null : new MimeType(this.mimeType));
  return new FileWrapperStore(path, this.mimeType, xdiReader, xdiWriter);
}

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

XDIReader reader = XDIReaderRegistry.forMimeType(recvMimeType);
  reader = XDIReaderRegistry.forMimeType(recvMimeType);
  reader = XDIReaderRegistry.forMimeType(new MimeType(contentType));

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

public void testReaders() throws Exception {
  String[] formats = new String[] { "XDI/JSON", "XDI DISPLAY" };
  String[] fileExtensions = new String[] { "json", "xdi" };
  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") };
  for (String format : formats) assertTrue(XDIReaderRegistry.forFormat(format, null).supportsFormat(format));
  for (String fileExtension : fileExtensions) assertTrue(XDIReaderRegistry.forFileExtension(fileExtension, null).supportsFileExtension(fileExtension));
  for (MimeType mimeType : mimeTypes) assertTrue(XDIReaderRegistry.forMimeType(mimeType).supportsMimeType(mimeType));
}

代码示例来源: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])));

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com