本文整理汇总了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();
}
示例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());
}
示例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");
}
示例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();
}
}
示例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();
}
}
}