List of usage examples for com.google.common.net MediaType OCTET_STREAM
MediaType OCTET_STREAM
To view the source code for com.google.common.net MediaType OCTET_STREAM.
Click Source Link
From source file:com.orange.clara.cloud.servicedbdumper.dbdumper.s3.UploadS3StreamImpl.java
@Override public String upload(InputStream content, Blob blob) throws IOException { String key = blob.getMetadata().getName(); ContentMetadata metadata = blob.getMetadata().getContentMetadata(); ObjectMetadataBuilder builder = ObjectMetadataBuilder.create().key(key) .contentType(MediaType.OCTET_STREAM.toString()).contentDisposition(key) .contentEncoding(metadata.getContentEncoding()).contentLanguage(metadata.getContentLanguage()) .userMetadata(blob.getMetadata().getUserMetadata()); String uploadId = this.s3Client.initiateMultipartUpload(bucketName, builder.build()); Integer partNum = 1;//from www. j a va2s . c o m Payload part = null; int bytesRead = 0; boolean shouldContinue = true; try { SortedMap<Integer, String> etags = Maps.newTreeMap(); while (shouldContinue) { byte[] chunk = new byte[CHUNK_SIZE]; bytesRead = ByteStreams.read(content, chunk, 0, chunk.length); if (bytesRead != chunk.length) { shouldContinue = false; chunk = Arrays.copyOf(chunk, bytesRead); } part = new ByteArrayPayload(chunk); prepareUploadPart(bucketName, key, uploadId, partNum, part, etags); partNum++; } return this.s3Client.completeMultipartUpload(bucketName, key, uploadId, etags); } catch (RuntimeException ex) { this.s3Client.abortMultipartUpload(bucketName, key, uploadId); throw ex; } }
From source file:com.orange.clara.cloud.poc.s3.upload.UploadS3StreamImpl.java
@Override public String upload(InputStream content, Blob blob) throws IOException { String bucketName = this.blobStoreContext.getSpringCloudBlobStore().getBucketName(); String key = blob.getMetadata().getName(); ContentMetadata metadata = blob.getMetadata().getContentMetadata(); ObjectMetadataBuilder builder = ObjectMetadataBuilder.create().key(key) .contentType(MediaType.OCTET_STREAM.toString()).contentDisposition(key) .contentEncoding(metadata.getContentEncoding()).contentLanguage(metadata.getContentLanguage()) .userMetadata(blob.getMetadata().getUserMetadata()); String uploadId = this.s3Client.initiateMultipartUpload(bucketName, builder.build()); Integer partNum = 1;//from w ww . java 2 s .c o m Payload part = null; int bytesRead = 0; boolean shouldContinue = true; try { SortedMap<Integer, String> etags = Maps.newTreeMap(); while (shouldContinue) { byte[] chunk = new byte[CHUNK_SIZE]; bytesRead = ByteStreams.read(content, chunk, 0, chunk.length); if (bytesRead != chunk.length) { shouldContinue = false; chunk = Arrays.copyOf(chunk, bytesRead); } part = new ByteArrayPayload(chunk); prepareUploadPart(bucketName, key, uploadId, partNum, part, etags); partNum++; } return this.s3Client.completeMultipartUpload(bucketName, key, uploadId, etags); } catch (RuntimeException ex) { this.s3Client.abortMultipartUpload(bucketName, key, uploadId); throw ex; } }
From source file:com.github.avarabyeu.restendpoint.serializer.ByteArraySerializer.java
@Override public final String getMimeType() { return MediaType.OCTET_STREAM.toString(); }
From source file:com.orange.clara.cloud.servicedbdumper.filer.s3uploader.UploadS3StreamImpl.java
@Override public String upload(InputStream content, Blob blob) throws IOException { String key = blob.getMetadata().getName(); String bucketName = this.blobStoreContext.getBucketName(); ContentMetadata metadata = blob.getMetadata().getContentMetadata(); ObjectMetadataBuilder builder = ObjectMetadataBuilder.create().key(key) .contentType(MediaType.OCTET_STREAM.toString()).contentDisposition(key) .contentEncoding(metadata.getContentEncoding()).contentLanguage(metadata.getContentLanguage()) .userMetadata(blob.getMetadata().getUserMetadata()); String uploadId = this.s3Client.initiateMultipartUpload(bucketName, builder.build()); Integer partNum = 1;//from w ww . j av a 2s . c o m Payload part = null; int bytesRead = 0; byte[] chunk = null; boolean shouldContinue = true; SortedMap<Integer, String> etags = Maps.newTreeMap(); try { while (shouldContinue) { chunk = new byte[chunkSize]; bytesRead = ByteStreams.read(content, chunk, 0, chunk.length); if (bytesRead != chunk.length) { shouldContinue = false; chunk = Arrays.copyOf(chunk, bytesRead); if (chunk.length == 0) { //something from jvm causing memory leak, we try to help jvm which seems working. //but PLEASE DON'T REPLICATE AT HOME ! chunk = null; part = null; System.gc(); // break; } } part = new ByteArrayPayload(chunk); prepareUploadPart(bucketName, key, uploadId, partNum, part, etags); partNum++; //something from jvm causing memory leak, we try to help jvm which seems working. //but PLEASE DON'T REPLICATE AT HOME ! chunk = null; part = null; System.gc(); // } return this.completeMultipartUpload(bucketName, key, uploadId, etags); } catch (RuntimeException ex) { this.s3Client.abortMultipartUpload(bucketName, key, uploadId); throw ex; } }
From source file:org.droidphy.core.network.raft.ResourceHandler.java
public AsyncHttpServer listen(int port) { server = new AsyncHttpServer() { @Override/* w ww.j a va2 s . c o m*/ protected AsyncHttpRequestBody onUnknownBody(Headers headers) { String contentType = headers.get("Content-Type"); if (contentType == null) { return null; } String[] values = contentType.split(";"); for (int i = 0; i < values.length; i++) { values[i] = values[i].trim(); } for (String ct : values) { if (MediaType.OCTET_STREAM.toString().equals(ct)) { return new OctetStreamBody(); } } return null; } }; // TODO: Add error handler!! server.post("/raft/init", new JsonStringServerRequestCallback<Raft.StateType, Void>() { @Override public Raft.StateType handle(Void aVoid) { try { return raft.init().get(); } catch (Throwable e) { throw Throwables.propagate(e); } } }); server.get("/raft/config", new JsonStringServerRequestCallback<ClusterConfig, Void>() { @Override public ClusterConfig handle(Void aVoid) { return clusterConfig; } }); server.get("/raft/state", new JsonStringServerRequestCallback<Raft.StateType, Void>() { @Override public Raft.StateType handle(Void aVoid) { return raft.type(); } }); server.post("/raft/vote", new JsonStringServerRequestCallback<RequestVoteResponse, RequestVote>() { @Override public RequestVoteResponse handle(RequestVote requestVote) { return raft.requestVote(requestVote); } }); server.post("/raft/entries", new JsonStringServerRequestCallback<AppendEntriesResponse, AppendEntries>() { @Override public AppendEntriesResponse handle(AppendEntries appendEntries) { return raft.appendEntries(appendEntries); } }); server.post("/raft/commit", new HttpServerRequestCallback() { @Override public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) { AsyncHttpRequestBody body = request.getBody(); if (!(body instanceof OctetStreamBody)) { Logger.w("Request body is not Octet Stream: " + body); return; } byte[] operation = ((OctetStreamBody) body).get(); try { raft.commitOperation(operation).get(); // "No Content" response.code(204).end(); } catch (NotLeaderException e) { // "Found" response.redirect(e.getLeader().toString()); } catch (Exception e) { throw Throwables.propagate(e); } } }); server.listen(port); return server; }
From source file:io.bazel.rules.closure.http.HttpMessage.java
public final MediaType getContentType() { return firstNonNull(contentType, MediaType.OCTET_STREAM); }
From source file:com.seleniumtests.connectors.selenium.SeleniumRobotGridConnector.java
/** * In case an app is required on the node running the test, upload it to the grid hub * This will then be made available through HTTP GET URL to the node (appium will receive an url instead of a file) * /*w ww . j ava2s . c o m*/ */ @Override public void uploadMobileApp(Capabilities caps) { String appPath = (String) caps.getCapability(MobileCapabilityType.APP); // check whether app is given and app path is a local file if (appPath != null && new File(appPath).isFile()) { try (CloseableHttpClient client = HttpClients.createDefault();) { // zip file List<File> appFiles = new ArrayList<>(); appFiles.add(new File(appPath)); File zipFile = FileUtility.createZipArchiveFromFiles(appFiles); HttpHost serverHost = new HttpHost(hubUrl.getHost(), hubUrl.getPort()); URIBuilder builder = new URIBuilder(); builder.setPath("/grid/admin/FileServlet/"); builder.addParameter("output", "app"); HttpPost httpPost = new HttpPost(builder.build()); httpPost.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.OCTET_STREAM.toString()); FileInputStream fileInputStream = new FileInputStream(zipFile); InputStreamEntity entity = new InputStreamEntity(fileInputStream); httpPost.setEntity(entity); CloseableHttpResponse response = client.execute(serverHost, httpPost); if (response.getStatusLine().getStatusCode() != 200) { throw new SeleniumGridException( "could not upload application file: " + response.getStatusLine().getReasonPhrase()); } else { // set path to the mobile application as an URL on the grid hub ((DesiredCapabilities) caps).setCapability(MobileCapabilityType.APP, IOUtils.toString(response.getEntity().getContent()) + "/" + appFiles.get(0).getName()); } } catch (IOException | URISyntaxException e) { throw new SeleniumGridException("could not upload application file", e); } } }
From source file:com.jivesoftware.jivesdk.impl.auth.jiveauth.JiveSignatureValidatorImpl.java
@Nonnull private RestPostRequest createValidationPostRequest(@Nonnull InstanceRegistrationRequest request) throws NoSuchAlgorithmException { Map<String, String> headers = Maps.newHashMap(); headers.put("X-Jive-MAC", request.getJiveSignature()); headers.put(HttpHeaders.CONTENT_TYPE, MediaType.OCTET_STREAM.toString()); String body = createSignatureValidationRequest(request); return RestRequestFactory.createPostRequestBuilder(request.getJiveSignatureURL()).withHeaders(headers) .withEntity(new StringEntity(body, ContentType.APPLICATION_OCTET_STREAM)); }
From source file:com.epam.reportportal.service.LoggingContext.java
LoggingContext(Maybe<String> itemId, final ReportPortalClient client, int bufferSize, boolean convertImages) { this.itemId = itemId; this.emitter = PublishSubject.create(); this.convertImages = convertImages; emitter.toFlowable(BackpressureStrategy.BUFFER) .flatMap(new Function<Maybe<SaveLogRQ>, Publisher<SaveLogRQ>>() { @Override//from w w w. j a va2 s. c o m public Publisher<SaveLogRQ> apply(Maybe<SaveLogRQ> rq) throws Exception { return rq.toFlowable(); } }).buffer(bufferSize).flatMap(new Function<List<SaveLogRQ>, Flowable<BatchSaveOperatingRS>>() { @Override public Flowable<BatchSaveOperatingRS> apply(List<SaveLogRQ> rqs) throws Exception { MultiPartRequest.Builder builder = new MultiPartRequest.Builder(); builder.addSerializedPart(Constants.LOG_REQUEST_JSON_PART, rqs); for (SaveLogRQ rq : rqs) { final SaveLogRQ.File file = rq.getFile(); if (null != file) { builder.addBinaryPart(Constants.LOG_REQUEST_BINARY_PART, file.getName(), Strings.isNullOrEmpty(file.getContentType()) ? MediaType.OCTET_STREAM.toString() : file.getContentType(), wrap(file.getContent())); } } return client.log(builder.build()).toFlowable(); } }).doOnError(new Consumer<Throwable>() { @Override public void accept(Throwable throwable) throws Exception { throwable.printStackTrace(); } }).observeOn(Schedulers.computation()).subscribe(logFlowableResults("Logging context")); }
From source file:com.seleniumtests.connectors.selenium.SeleniumRobotGridConnector.java
/** * Upload a file given file path// w ww . j a v a 2 s .c o m * @param filePath */ @Override public void uploadFile(String filePath) { try (CloseableHttpClient client = HttpClients.createDefault();) { // zip file List<File> appFiles = new ArrayList<>(); appFiles.add(new File(filePath)); File zipFile = FileUtility.createZipArchiveFromFiles(appFiles); HttpHost serverHost = new HttpHost(hubUrl.getHost(), hubUrl.getPort()); URIBuilder builder = new URIBuilder(); builder.setPath("/grid/admin/FileServlet/"); builder.addParameter("output", "app"); HttpPost httpPost = new HttpPost(builder.build()); httpPost.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.OCTET_STREAM.toString()); FileInputStream fileInputStream = new FileInputStream(zipFile); InputStreamEntity entity = new InputStreamEntity(fileInputStream); httpPost.setEntity(entity); CloseableHttpResponse response = client.execute(serverHost, httpPost); if (response.getStatusLine().getStatusCode() != 200) { throw new SeleniumGridException( "could not upload file: " + response.getStatusLine().getReasonPhrase()); } else { // TODO call remote API throw new NotImplementedException("call remote Robot to really upload file"); } } catch (IOException | URISyntaxException e) { throw new SeleniumGridException("could not upload file", e); } }