本文整理了Java中org.apache.jackrabbit.oak.commons.IOUtils.copy()
方法的一些代码示例,展示了IOUtils.copy()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.copy()
方法的具体详情如下:
包路径:org.apache.jackrabbit.oak.commons.IOUtils
类名称:IOUtils
方法名:copy
[英]Copy bytes from an InputStream to an OutputStream.
This method buffers the input internally, so there is no need to use a BufferedInputStream.
[中]将字节从InputStream复制到OutputStream。
此方法在内部缓冲输入,因此无需使用BufferedInputStream。
代码示例来源:origin: apache/jackrabbit-oak
private void copy(String resource, String dir) throws IOException {
String fileName = dir + resource.substring(resource.lastIndexOf("/"));
File outputFile = new File(fileName);
if (outputFile.createNewFile()) {
InputStream inputStream = null;
FileOutputStream outputStream = null;
try {
inputStream = getClass().getResourceAsStream(resource);
outputStream = new FileOutputStream(outputFile);
IOUtils.copy(inputStream, outputStream);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (Exception e) {
// do nothing
}
}
if (outputStream != null) {
try {
outputStream.close();
} catch (Exception e) {
// do nothing
}
}
}
}
}
代码示例来源:origin: org.apache.jackrabbit/oak-solr-core
private void copy(String resource, String dir) throws IOException {
String fileName = dir + resource.substring(resource.lastIndexOf("/"));
File outputFile = new File(fileName);
if (outputFile.createNewFile()) {
InputStream inputStream = null;
FileOutputStream outputStream = null;
try {
inputStream = getClass().getResourceAsStream(resource);
outputStream = new FileOutputStream(outputFile);
IOUtils.copy(inputStream, outputStream);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (Exception e) {
// do nothing
}
}
if (outputStream != null) {
try {
outputStream.close();
} catch (Exception e) {
// do nothing
}
}
}
}
}
代码示例来源:origin: org.apache.jackrabbit/oak-mk-remote
public String getParameter(String name) throws IOException {
if (!paramsChecked) {
try {
String contentType = getContentType();
if ("application/x-www-form-urlencoded".equals(contentType)) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(getInputStream(), out);
collectParameters(out.toString(), params);
}
} finally {
paramsChecked = true;
}
}
return params.get(name);
}
代码示例来源:origin: org.apache.jackrabbit/oak-mk-remote
/**
* Execute the request.
*
* @throws IOException if an I/O error occurs
*/
private byte[] execute() throws IOException {
HttpExecutor executor = new HttpExecutor(socketFactory, socketAddress);
try {
InputStream stream = executor.execute(command, params, in);
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
IOUtils.copy(stream, buffer);
return buffer.toByteArray();
} finally {
stream.close();
}
} finally {
executor.close();
}
}
代码示例来源:origin: apache/jackrabbit-oak
private void createOak16GCLog() throws IOException {
try (InputStream source = GcJournalTest.class.getResourceAsStream("oak-1.6-gc.log")) {
try (FileOutputStream target = new FileOutputStream(segmentFolder.newFile("gc.log"))) {
IOUtils.copy(source, target);
}
}
}
代码示例来源:origin: apache/jackrabbit-oak
public void testCopyStream() throws IOException {
final Random r = new Random(1);
for (int length : Lists.newArrayList(0, 1, 1000, 4096, 4097, 1024*1024)) {
byte[] inData = new byte[length];
r.nextBytes(inData);
ByteArrayInputStream in = new ByteArrayInputStream(inData);
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(in, out);
assertEquals(inData, out.toByteArray());
}
}
代码示例来源:origin: org.apache.jackrabbit/oak-mk-remote
@Override
public void service(Request request, Response response) throws IOException {
String file = request.getFile();
if (file.endsWith("/")) {
file += "index.html";
}
InputStream in = FileServlet.class.getResourceAsStream(file.substring(1));
if (in != null) {
try {
int dotIndex = file.lastIndexOf('.');
if (dotIndex != -1) {
String contentType = MIME_TYPES.get(file.substring(dotIndex + 1));
if (contentType == null) {
contentType = "application/octet-stream";
}
response.setContentType(contentType);
}
IOUtils.copy(in, response.getOutputStream());
} finally {
IOUtils.closeQuietly(in);
}
} else {
response.setStatusCode(404);
}
}
代码示例来源:origin: org.apache.jackrabbit/oak-mk-remote
bodyOut.write("Content-Type: application/octet-stream\r\n".getBytes());
bodyOut.write("\r\n".getBytes());
IOUtils.copy(in, bodyOut);
bodyOut.write("\r\n".getBytes());
bodyOut.write("--".getBytes());
代码示例来源:origin: apache/jackrabbit-oak
/**
* Uploads data via HTTP put to the provided URI.
*
* @param uri The URI to upload to.
* @param contentLength Value to set in the Content-Length header.
* @param in - The input stream to upload.
* @return HTTP response code from the upload request. Note that a successful
* response for S3 is 200 - OK whereas for Azure it is 201 - Created.
* @throws IOException
*/
public static int httpPut(@Nullable URI uri, long contentLength, InputStream in) throws IOException {
// this weird combination of @Nullable and assertNotNull() is for IDEs not warning in test methods
assertNotNull(uri);
HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("PUT");
connection.setRequestProperty("Content-Length", String.valueOf(contentLength));
connection.setRequestProperty("Date", DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssX")
.withZone(ZoneOffset.UTC)
.format(Instant.now()));
OutputStream putStream = connection.getOutputStream();
IOUtils.copy(in, putStream);
putStream.close();
return connection.getResponseCode();
}
代码示例来源:origin: org.apache.jackrabbit/oak-mk-remote
@Override
public void execute(MicroKernel mk, Request request, Response response)
throws IOException, MicroKernelException {
String blobId = request.getParameter("blob_id", "");
long pos = request.getParameter("pos", 0L);
int length = request.getParameter("length", -1);
if (request.getUserAgent() == null) {
// let browsers guess the correct file format
response.setContentType("application/octet-stream");
}
OutputStream out = response.getOutputStream();
if (pos == 0L && length == -1) {
/* return the complete binary */
InputStream in = new MicroKernelInputStream(mk, blobId);
IOUtils.copy(in, out);
} else {
/* return some range */
byte[] buff = new byte[length];
int count = mk.read(blobId, pos, buff, 0, length);
if (count > 0) {
out.write(buff, 0, count);
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!