gpt4 book ai didi

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

转载 作者:知者 更新时间:2024-03-24 02:41:05 29 4
gpt4 key购买 nike

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

XDIWriter.getMimeType介绍

[英]Returns the mime type this XDIWriter can write, e.g.

  • text/plain
  • application/xdi+json
    [中]返回此XDIWriter可以编写的mime类型,例如。
    *文本/纯文本
    *application/xdi+json

代码示例

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

public static void addWriter(Class<? extends XDIWriter> writerClass) {
  XDIWriter writer;
  try {
    Constructor<? extends XDIWriter> constructor = writerClass.getConstructor(Properties.class);
    writer = constructor.newInstance((Properties) null);
  } catch (Exception ex) {
    throw new RuntimeException(ex);
  }
  String format = writer.getFormat();
  String fileExtension = writer.getFileExtension();
  MimeType mimeType = writer.getMimeType();
  if (format != null) writerClassesByFormat.put(format, writerClass);
  if (fileExtension != null) writerClassesByFileExtension.put(fileExtension, writerClass);
  if (mimeType != null) writerClassesByMimeType.put(mimeType, writerClass);
}

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

private void sendOk(HttpTransportRequest request, HttpTransportResponse response, TransportMessagingResponse messagingResponse) throws IOException {
  response.setStatus(HttpTransportResponse.SC_OK);
  Map<String, String> headers = new HashMap<String, String> ();
  headers.putAll(this.getHeaders());
  if (HttpTransportRequest.METHOD_GET.equals(request.getMethod())) headers.putAll(this.getHeadersGet());
  if (HttpTransportRequest.METHOD_POST.equals(request.getMethod())) headers.putAll(this.getHeadersPost());
  if (HttpTransportRequest.METHOD_PUT.equals(request.getMethod())) headers.putAll(this.getHeadersPut());
  if (HttpTransportRequest.METHOD_DELETE.equals(request.getMethod())) headers.putAll(this.getHeadersDelete());
  if (HttpTransportRequest.METHOD_OPTIONS.equals(request.getMethod())) headers.putAll(this.getHeadersOptions());
  for (Map.Entry<String, String> header : headers.entrySet()) {
    response.setHeader(header.getKey(), header.getValue());
  }
  if (messagingResponse != null) {
    // find a suitable writer based on accept headers
    if (log.isDebugEnabled()) log.debug("Accept: " + request.getHeader("Accept"));
    XDIWriter writer = null;
    String acceptHeader = request.getHeader("Accept");
    MimeType sendMimeType = acceptHeader != null ? AcceptHeader.parse(acceptHeader).bestMimeType(false, true) : null;
    writer = sendMimeType != null ? XDIWriterRegistry.forMimeType(sendMimeType) : null;
    if (writer == null) writer = XDIWriterRegistry.getDefault();
    // send out the message result
    if (log.isDebugEnabled()) log.debug("Sending result in " + sendMimeType + " with writer " + writer.getClass().getSimpleName() + ".");
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    writer.write(messagingResponse.getGraph(), buffer);
    response.setContentType(writer.getMimeType().toString());
    response.setContentLength(buffer.size());
    response.writeBody(buffer.toByteArray(), true);
  }
  if (log.isDebugEnabled()) log.debug("Output complete.");
}

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