gpt4 book ai didi

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

转载 作者:知者 更新时间:2024-03-26 09:45:05 27 4
gpt4 key购买 nike

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

XDIReaderRegistry.getDefault介绍

[英]Returns an XDIReader for the default format.
[中]返回默认格式的XDIReader。

代码示例

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

/**
 * Returns an XDIReader for the specified file extension, e.g.
 * <ul>
 * <ul>
 * <li>.json</li>
 * <li>.xdi</li>
 * </ul>
 * </ul>
 * @param fileExtension The desired file extension.
 * @return An XDIReader, or null if no appropriate implementation could be found.
 */
public static XDIReader forFileExtension(String fileExtension, Properties parameters) {
  if (fileExtension == null) return XDIReaderRegistry.getDefault();
  Class<? extends XDIReader> readerClass = readerClassesByFileExtension.get(fileExtension);
  if (readerClass == null) return null;
  try {
    Constructor<? extends XDIReader> constructor = readerClass.getConstructor(Properties.class);
    return constructor.newInstance(parameters);
  } catch (Exception ex) {
    throw new RuntimeException(ex);
  }
}

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

/**
 * Returns an XDIReader for the specified format, e.g.
 * <ul>
 * <li>XDI/JSON</li>
 * <li>XDI DISPLAY</li>
 * </ul>
 * @return An XDIReader, or null if no appropriate implementation could be found.
 */
public static XDIReader forFormat(String format, Properties parameters) {
  if (format == null) return XDIReaderRegistry.getDefault();
  if (AutoReader.FORMAT_NAME.equalsIgnoreCase(format)) return getAuto();
  Class<? extends XDIReader> readerClass = readerClassesByFormat.get(format);
  if (readerClass == null) return null;
  try {
    Constructor<? extends XDIReader> constructor = readerClass.getConstructor(Properties.class);
    return constructor.newInstance(parameters);
  } catch (Exception ex) {
    throw new RuntimeException(ex);
  }
}

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

/**
 * Returns an XDIReader for the specified mime type, e.g.
 * <ul>
 * <li>application/xdi+json</li>
 * <li>text/xdi</li>
 * </ul>
 * @param mimeType The desired mime type.
 * @return An XDIReader, or null if no appropriate implementation could be found.
 */
public static XDIReader forMimeType(MimeType mimeType) {
  if (mimeType == null) return XDIReaderRegistry.getDefault();
  Class<? extends XDIReader> readerClass = readerClassesByMimeType.get(mimeType.mimeTypeWithoutParameters());
  if (readerClass == null) return null;
  try {
    Constructor<? extends XDIReader> constructor = readerClass.getConstructor(Properties.class);
    return constructor.newInstance(mimeType.getParameters());
  } catch (Exception ex) {
    throw new RuntimeException(ex);
  }
}

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

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

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

public void testDefaults() throws Exception {
  assertNotNull(XDIReaderRegistry.getDefault());
  assertNotNull(XDIWriterRegistry.getDefault());
}

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