当前位置: 首页>>代码示例>>Java>>正文


Java Channels.newWriter方法代码示例

本文整理汇总了Java中java.nio.channels.Channels.newWriter方法的典型用法代码示例。如果您正苦于以下问题:Java Channels.newWriter方法的具体用法?Java Channels.newWriter怎么用?Java Channels.newWriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.channels.Channels的用法示例。


在下文中一共展示了Channels.newWriter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import java.nio.channels.Channels; //导入方法依赖的package包/类
public void run(OutputStream optionalOutput, boolean extractUnpublished) throws IOException {
  // fill sources with extra input:
  JsonDataSources sources = new ExtraInput().fetchAllDataSources();
  // fill sources with vendor API input:
  VendorDynamicInput vendorInput = new VendorDynamicInput();
  vendorInput.setExtractUnpublished(extractUnpublished);
  sources.putAll(vendorInput.fetchAllDataSources());
  // extract session data from inputs:
  JsonObject newData = new DataExtractor(false).extractFromDataSources(sources);

  // send data to the outputstream
  Writer writer = Channels.newWriter(Channels.newChannel(optionalOutput), "UTF-8");
  JsonWriter optionalOutputWriter = new JsonWriter(writer);
  optionalOutputWriter.setIndent("  ");
  new Gson().toJson(newData, optionalOutputWriter);
  optionalOutputWriter.flush();
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:18,代码来源:APIExtractor.java

示例2: createOrUpdate

import java.nio.channels.Channels; //导入方法依赖的package包/类
/**
 * Create or update a file in a GCC bucket, using the default ACL for the bucket.
 *
 * @param filename Name of file to create
 * @param contents File contents
 * @param shortCache If true, sets cache expiry to 0 sec. Otherwise, cache expiry is set to 6,000 sec.
 * @throws IOException
 */
public void createOrUpdate(String filename, JsonElement contents, boolean shortCache)
    throws IOException {
  GcsFilename file = new GcsFilename(defaultBucket, filename);
  GcsFileOptions options = new GcsFileOptions.Builder()
    .mimeType("application/json")
    .cacheControl("public, max-age="+(shortCache?0:6000))
    .build();
  GcsOutputChannel writeChannel = null;
  try {
    writeChannel = gcsService.createOrReplace(file, options);
    Writer writer = Channels.newWriter(writeChannel, DEFAULT_CHARSET_NAME);
    new Gson().toJson(contents, writer);
    writer.flush();
  } finally {
    if (writeChannel != null) {
      writeChannel.close();
    }
  }
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:28,代码来源:CloudFileManager.java

示例3: stop

import java.nio.channels.Channels; //导入方法依赖的package包/类
private void stop() {
  try (
      SocketChannel socket = SocketChannel.open();
      PrintWriter writer = new PrintWriter(Channels.newWriter(socket, StandardCharsets.UTF_8.name()), true);
      BufferedReader reader = new BufferedReader(Channels.newReader(socket, StandardCharsets.UTF_8.name()))) {
    socket.connect(new InetSocketAddress("localhost", controlPort));
  } catch (IOException e) {
    // bury
  }
}
 
开发者ID:gradle-clojure,项目名称:gradle-clojure,代码行数:11,代码来源:ClojureNRepl.java

示例4: createUnderlyingLogWriter

import java.nio.channels.Channels; //导入方法依赖的package包/类
protected Writer createUnderlyingLogWriter(String transferId)
{
    if (reportFile == null)
    {
        reportFile = createTransferRecord(transferId);
    }
    ContentWriter contentWriter = contentService.getWriter(reportFile, ContentModel.PROP_CONTENT, true);
    contentWriter.setMimetype(MimetypeMap.MIMETYPE_XML);
    contentWriter.setEncoding("UTF-8");
    return Channels.newWriter(contentWriter.getWritableChannel(), "UTF-8");
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:12,代码来源:TransferSummaryReportImpl.java

示例5: createUnderlyingLogWriter

import java.nio.channels.Channels; //导入方法依赖的package包/类
@Override
protected Writer createUnderlyingLogWriter(String transferId)
{
    NodeRef node = new NodeRef(transferId);
    ContentWriter contentWriter = contentService.getWriter(node, ContentModel.PROP_CONTENT, true);
    contentWriter.setMimetype(MimetypeMap.MIMETYPE_XML);
    contentWriter.setEncoding("UTF-8");
    return Channels.newWriter(contentWriter.getWritableChannel(), "UTF-8");
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:10,代码来源:RepoTransferProgressMonitorImpl.java

示例6: createUnderlyingLogWriter

import java.nio.channels.Channels; //导入方法依赖的package包/类
@Override
protected Writer createUnderlyingLogWriter(String transferId)
{
    File logFile = getReportFile(transferId);
    try
    {
        return Channels.newWriter(Channels.newChannel(new FileOutputStream(logFile)), "UTF-8");
    }
    catch (FileNotFoundException e)
    {
        throw new TransferFatalException("error.unableToOpenTransferReport", e);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-file-transfer-receiver,代码行数:14,代码来源:FileTransferProgressMonitor.java

示例7: run

import java.nio.channels.Channels; //导入方法依赖的package包/类
@Override
public void run() {
  logger.debug("Starting connection handler");
  Event event = null;

  try {
    Reader reader = Channels.newReader(socketChannel, sourceEncoding);
    Writer writer = Channels.newWriter(socketChannel, sourceEncoding);
    CharBuffer buffer = CharBuffer.allocate(maxLineLength);
    buffer.flip(); // flip() so fill() sees buffer as initially empty

    while (true) {
      // this method blocks until new data is available in the socket
      int charsRead = fill(buffer, reader);
      logger.debug("Chars read = {}", charsRead);

      // attempt to process all the events in the buffer
      int eventsProcessed = processEvents(buffer, writer);
      logger.debug("Events processed = {}", eventsProcessed);

      if (charsRead == -1) {
        // if we received EOF before last event processing attempt, then we
        // have done everything we can
        break;
      } else if (charsRead == 0 && eventsProcessed == 0) {
        if (buffer.remaining() == buffer.capacity()) {
          // If we get here it means:
          // 1. Last time we called fill(), no new chars were buffered
          // 2. After that, we failed to process any events => no newlines
          // 3. The unread data in the buffer == the size of the buffer
          // Therefore, we are stuck because the client sent a line longer
          // than the size of the buffer. Response: Drop the connection.
          logger.warn("Client sent event exceeding the maximum length");
          counterGroup.incrementAndGet("events.failed");
          writer.write("FAILED: Event exceeds the maximum length (" +
              buffer.capacity() + " chars, including newline)\n");
          writer.flush();
          break;
        }
      }
    }

    socketChannel.close();

    counterGroup.incrementAndGet("sessions.completed");
  } catch (IOException e) {
    counterGroup.incrementAndGet("sessions.broken");
    try {
      socketChannel.close();
    } catch (IOException ex) {
      logger.error("Unable to close socket channel. Exception follows.", ex);
    }
  }

  logger.debug("Connection handler exiting");
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:57,代码来源:NetcatSource.java

示例8: process

import java.nio.channels.Channels; //导入方法依赖的package包/类
private void process(HttpServletResponse resp, boolean showOnly) throws IOException {
  // everything ok, let's update
  StringBuilder summary = new StringBuilder();
  JsonObject contents = new JsonObject();
  JsonDataSources sources = new VendorDynamicInput().fetchAllDataSources();
  for (String entity: sources) {
    JsonArray array = new JsonArray();
    JsonDataSource source = sources.getSource(entity);
    for (JsonObject obj: source) {
      array.add(obj);
    }
    summary.append(entity).append(": ").append(source.size()).append("\n");
    contents.add(entity, array);
  }

  if (showOnly) {
    // Show generated contents to the output
    resp.setContentType("application/json");
    Writer writer = Channels.newWriter(Channels.newChannel(resp.getOutputStream()), "UTF-8");
    JsonWriter outputWriter = new JsonWriter(writer);
    outputWriter.setIndent("  ");
    new Gson().toJson(contents, outputWriter);
    outputWriter.flush();

  } else {
    // Write file to cloud storage
    CloudFileManager fileManager = new CloudFileManager();
    fileManager.createOrUpdate("__raw_session_data.json", contents, true);

    // send email
    Message message = new Message();
    message.setSender(Config.EMAIL_FROM);
    message.setSubject("[iosched-data-update] Manual sync from CMS");
    message.setTextBody(
        "Hey,\n\n"
        + "(this message is autogenerated)\n"
        + "This is a heads up that "+userService.getCurrentUser().getEmail()+" has just updated the IOSched 2015 data from the Vendor CMS.\n\n"
            + "Here is a brief status of what has been extracted from the Vendor API:\n"
            + summary
            + "\n\n"
            + "If you want to check the most current data that will soon be sync'ed to the IOSched Android app, "
            + "check this link: http://storage.googleapis.com/iosched-updater-dev.appspot.com/__raw_session_data.json\n"
            + "This data will remain unchanged until someone with proper privileges updates it again on https://iosched-updater-dev.appspot.com/cmsupdate\n\n"
            + "Thanks!\n\n"
            + "A robot on behalf of the IOSched team!\n\n"
            + "PS: you are receiving this either because you are an admin of the IOSched project or "
            + "because you are in a hard-coded list of I/O organizers. If you don't want to "
            + "receive it anymore, pay me a beer and ask kindly.");
    MailServiceFactory.getMailService().sendToAdmins(message);

    resp.sendRedirect("/admin/schedule/updateok.html");
  }
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:54,代码来源:CMSUpdateServlet.java


注:本文中的java.nio.channels.Channels.newWriter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。