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


Java ByteArrayOutputStream.close方法代码示例

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


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

示例1: convertBufferToBytes

import org.apache.commons.io.output.ByteArrayOutputStream; //导入方法依赖的package包/类
/**
 * Converts a BufferedInputStream to a byte array
 *
 * @param inputStream
 * @param bufferLength
 * @return
 * @throws IOException
 */
private byte[] convertBufferToBytes(BufferedInputStream inputStream, int bufferLength) throws IOException {
    if (inputStream == null)
        return null;
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    byte[] buffer = new byte[bufferLength];
    int x = inputStream.read(buffer, 0, bufferLength);
    Log.i("GraphServiceController", "bytes read from picture input stream " + String.valueOf(x));

    int n = 0;
    try {
        while ((n = inputStream.read(buffer, 0, bufferLength)) >= 0) {
            outputStream.write(buffer, 0, n);
        }
        inputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    outputStream.close();
    return outputStream.toByteArray();
}
 
开发者ID:microsoftgraph,项目名称:android-java-connect-sample,代码行数:30,代码来源:GraphServiceController.java

示例2: testAdd

import org.apache.commons.io.output.ByteArrayOutputStream; //导入方法依赖的package包/类
@Test
public void testAdd() throws IOException, TransportException {
  S3TransportSerializer serializer = mock(S3TransportSerializer.class);
  doReturn("foo".getBytes()).when(serializer).serialize(any(InternalEvent.class));
  S3TransportBuffer buffer = new S3TransportBuffer(5, false, serializer);

  InternalEvent mockEvent = mock(InternalEvent.class);
  buffer.add(mockEvent);

  ByteArrayOutputStream baos = buffer.getInternalBuffer();
  baos.close();

  String actual = new String(baos.toByteArray());
  assertEquals("foo", actual);
  assertEquals(false, buffer.isEmpty());
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:17,代码来源:S3TransportBufferTest.java

示例3: getCurrentScreen

import org.apache.commons.io.output.ByteArrayOutputStream; //导入方法依赖的package包/类
public Pair<ProcessingLifecycleStatus, byte[]> getCurrentScreen(final ProcessingLifecycleStatus status, final AssumedScreenTest screenTest) throws ApplicationDownException, IOException {
    if(!processManager.isMtgoRunningOrLoading()) {
        throw new ApplicationDownException("MTGO is not running!");
    }

    BufferedImage bi = robot.createScreenCapture(new Rectangle(0, 0, screenWidth, screenHeight));

    if(bi != null) {
        RawLines rawLines;

        if (screenTest == AssumedScreenTest.NOT_NEEDED) {
            rawLines = tesseractWrapper.getRawText(bi);
        } else {
            rawLines = tesseractWrapper.getRawText(bi, screenTest.getScreenTestBounds());
        }

        logger.info("Processing raw lines");
        final ProcessingLifecycleStatus outcomeStatus = rawLinesProcessor.determineLifecycleStatus(rawLines);
        logger.info("Determined new status: " + status.name());

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(bi, "jpg", baos);
        baos.flush();
        byte[] imageAsByteArray = baos.toByteArray();
        baos.close();

        return new ImmutablePair<>(outcomeStatus, imageAsByteArray);
    }

    throw new ApplicationDownException("Somehow made it to this unreachable point");
}
 
开发者ID:corydissinger,项目名称:mtgo-best-bot,代码行数:32,代码来源:RobotWrapper.java

示例4: getEvents

import org.apache.commons.io.output.ByteArrayOutputStream; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public List<Event> getEvents(HttpServletRequest request) throws Exception {
  Map<String, String> headers = new HashMap<String, String>();

  InputStream inputStream = request.getInputStream();

  Map<String, String[]> parameters = request.getParameterMap();
  for (String parameter : parameters.keySet()) {
    String value = parameters.get(parameter)[0];
    if (LOG.isDebugEnabled() && LogPrivacyUtil.allowLogRawData()) {
      LOG.debug("Setting Header [Key, Value] as [{},{}] ", parameter, value);
    }
    headers.put(parameter, value);
  }

  for (String header : mandatoryHeaders) {
    Preconditions.checkArgument(headers.containsKey(header),
        "Please specify " + header + " parameter in the request.");
  }

  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  try {
    IOUtils.copy(inputStream, outputStream);
    LOG.debug("Building an Event with stream of size -- {}", outputStream.size());
    Event event = EventBuilder.withBody(outputStream.toByteArray(), headers);
    event.setHeaders(headers);
    List<Event> eventList = new ArrayList<Event>();
    eventList.add(event);
    return eventList;
  } finally {
    outputStream.close();
    inputStream.close();
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:39,代码来源:BLOBHandler.java

示例5: writeNiFiPropertiesFile

import org.apache.commons.io.output.ByteArrayOutputStream; //导入方法依赖的package包/类
protected static void writeNiFiPropertiesFile(ByteArrayOutputStream nifiPropertiesOutputStream, String destPath) throws IOException {
    final Path nifiPropertiesPath = Paths.get(destPath, "nifi.properties");
    try (FileOutputStream nifiProperties = new FileOutputStream(nifiPropertiesPath.toString())) {
        nifiPropertiesOutputStream.writeTo(nifiProperties);
    } finally {
        if (nifiPropertiesOutputStream != null) {
            nifiPropertiesOutputStream.flush();
            nifiPropertiesOutputStream.close();
        }
    }
}
 
开发者ID:apache,项目名称:nifi-minifi,代码行数:12,代码来源:ConfigTransformer.java


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