String uploadPhotoContent(InputStream inputStream) throws IOException { // TODO: add filename InputStreamContent content = new InputStreamContent(null, inputStream); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); content.writeTo(outputStream); byte[] contentBytes = outputStream.toByteArray(); HttpContent httpContent = new ByteArrayContent(null, contentBytes); return makePostRequest(BASE_URL + "uploads/", Optional.of(PHOTO_UPLOAD_PARAMS), httpContent, String.class); }
/** Posts an RDF model to a Solid server. **/ public String postContent( String url, String slug, String type, Model model) throws IOException { StringWriter stringWriter = new StringWriter(); model.write(stringWriter, "TURTLE"); HttpContent content = new ByteArrayContent("text/turtle", stringWriter.toString().getBytes()); HttpRequest postRequest = factory.buildPostRequest( new GenericUrl(url), content); HttpHeaders headers = new HttpHeaders(); headers.setCookie(authCookie); headers.set("Link", "<" + type + ">; rel=\"type\""); headers.set("Slug", slug); postRequest.setHeaders(headers); HttpResponse response = postRequest.execute(); validateResponse(response, 201); return response.getHeaders().getLocation(); }
bigquery .getRequestFactory() .buildPutRequest(url, new ByteArrayContent(null, toWrite, toWriteOffset, length)); httpRequest.setParser(bigquery.getObjectParser()); long limit = destOffset + length;
public void close() throws IOException { File file = new File(); file.setName( getName().getBaseName() ); if ( parent != null ) { file.setParents( Collections.singletonList( parent.getId() ) ); } ByteArrayContent fileContent = new ByteArrayContent( "application/octet-stream", toByteArray() ); if ( count > 0 ) { driveService.files().create( file, fileContent ).execute(); ( (GoogleDriveFileSystem) getFileSystem() ).clearFileFromCache( getName() ); } } };
storage .getRequestFactory() .buildPutRequest(url, new ByteArrayContent(null, toWrite, toWriteOffset, length)); long limit = destOffset + length; StringBuilder range = new StringBuilder("bytes ");
byte[] bytes = kayentaObjectMapper.writeValueAsBytes(obj); StorageObject object = new StorageObject().setBucket(bucketName).setName(path); ByteArrayContent content = new ByteArrayContent("application/json", bytes);
/** * Creates an input stream content instance from the given input. */ InputStreamMediaProvider( byte[] array ) { this.content = new ByteArrayContent( null, array ); }
/** * Creates an input stream content instance from the given input. */ InputStreamMediaProvider( byte[] media, String type ) { this.content = new ByteArrayContent( type, media ); }
/** * Creates an input stream content instance from the given input. */ InputStreamMediaProvider( byte[] array, int offset, int length ) { this.content = new ByteArrayContent( null, array, offset, length ); }
/** * Creates an input stream content instance from the given input. */ InputStreamMediaProvider( byte[] array, int offset, int length, String type ) { this.content = new ByteArrayContent( type, array, offset, length ); }
import com.google.api.client.http.ByteArrayContent; import com.google.api.client.http.MultipartContent; import com.google.api.client.http.MultipartContent.Part; public class PartTest { public static void main(String[] arg){ Part part = new MultipartContent.Part( new ByteArrayContent(null, "your data is in here".getBytes())); }
ByteArrayOutputStream out = new ByteArrayOutputStream(); // use out File file = drive.files().create(fileMetadata, new ByteArrayContent("", out.toByteArray())).setFields("id").execute();
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); mimeMessage.writeTo(bytes); ByteArrayContent content = new ByteArrayContent("message/rfc822", bytes.toByteArray()); service.users().messages().send(from, null, content).execute();
private async Task<string> RequestCitasAsync() { var url = "http://192.168.1.126:8081/citas/get"; byte[] parametros = Encoding.UTF8.GetBytes("usersID=97"); var httpClient = new HttpClient(); var response = await httpClient.PostAsync(url, new ByteArrayContent(parametros)); return await response.Content.ReadAsStringAsync(); }
@SuppressWarnings("unchecked") @Override public ByteArrayContent getHttpContent(BatchJobMutateRequestInterface request, boolean isFirstRequest, boolean isLastRequest) throws BatchJobException { JaxBSerializer<RequestT> serializer = new JaxBSerializer<RequestT>(requestClass, requestQName); String serializedRequest = serializer.serialize((RequestT) request, false); return new ByteArrayContent("application/xml", serializedRequest.getBytes(UTF_8)); } }
void writeBytes(String name, byte[] contents) { name = String.join("/", rootFolder, name); try { StorageObject object = new StorageObject() .setBucket(bucketId) .setName(name); ByteArrayContent content = new ByteArrayContent("application/text", contents); storage.objects().insert(bucketId, object, content).execute(); } catch (IOException e) { throw new HalException(Problem.Severity.FATAL, "Failed to write to " + name + ": " + e.getMessage(), e); } }
HttpTransport httpTransport = new NetHttpTransport(); HttpRequestFactory httpRequestFactory = httpTransport.createRequestFactory(); String data = "query=" + query; HttpContent content = new ByteArrayContent("application/x-www-form-urlencoded", data.getBytes()); GenericUrl url = new GenericUrl("https://www.googleapis.com/freebase/v1/mqlread"); HttpRequest request = httpRequestFactory.buildPostRequest(url, content); HttpHeaders headers = new HttpHeaders(); headers.put("X-HTTP-Method-Override","GET"); request.setHeaders(headers); HttpResponse response = request.execute();
public void intercept(HttpRequest request) throws IOException { if (overrideThisMethod(request)) { HttpMethod method = request.method; request.method = HttpMethod.POST; request.headers.set("X-HTTP-Method-Override", method.name()); // Google servers will fail to process a POST unless the Content-Length header >= 1 if (request.content == null || request.content.getLength() == 0) { request.content = new ByteArrayContent(" "); } } }
void writeBytes(String name, byte[] contents) { name = String.join("/", rootFolder, name); try { StorageObject object = new StorageObject() .setBucket(bucketId) .setName(name); ByteArrayContent content = new ByteArrayContent("application/text", contents); storage.objects().insert(bucketId, object, content).execute(); } catch (IOException e) { throw new HalException(Problem.Severity.FATAL, "Failed to write to " + name + ": " + e.getMessage(), e); } }
@Test public void testNoResponseBodySet_fails() throws IOException { HttpRequest request = mockHttpServer .getHttpTransport() .createRequestFactory() .buildGetRequest(new GenericUrl(mockHttpServer.getServerUrl())); request.setContent(new ByteArrayContent("text", "test content".getBytes(UTF_8))); thrown.expect(HttpResponseException.class); thrown.expectMessage("No mock response"); request.execute(); }