當前位置: 首頁>>代碼示例>>Java>>正文


Java InputStreamContent類代碼示例

本文整理匯總了Java中com.google.api.client.http.InputStreamContent的典型用法代碼示例。如果您正苦於以下問題:Java InputStreamContent類的具體用法?Java InputStreamContent怎麽用?Java InputStreamContent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


InputStreamContent類屬於com.google.api.client.http包,在下文中一共展示了InputStreamContent類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: PostOrderWithTokensOnly

import com.google.api.client.http.InputStreamContent; //導入依賴的package包/類
/**
 * Post an order using the token and secret token to authenticate in DEAL.
 * To demonstrate successful authentication a POST request is executed.
 * 
 * @param messageToBePosted the JSON string representing the order
 * @return the result of the post action
 * 
 * @throws Exception on an exception occurring
 */
public static String PostOrderWithTokensOnly(String messageToBePosted)
		throws Exception
{
	// utilize accessToken to access protected resource in DEAL
	HttpRequestFactory factory = TRANSPORT
			.createRequestFactory(getParameters());
	GenericUrl url = new GenericUrl(PROTECTED_ORDERS_URL);
	InputStream stream = new ByteArrayInputStream(
			messageToBePosted.getBytes());
	InputStreamContent content = new InputStreamContent(JSON_IDENTIFIER,
			stream);
	HttpRequest req = factory.buildPostRequest(url, content);

	HttpResponse resp = req.execute();
	String response = resp.parseAsString();

	// log the response
	if (resp.getStatusCode() != 200 && LOG.isInfoEnabled())
	{
		LOG.info("Response Status Code: " + resp.getStatusCode());
		LOG.info("Response body:" + response);
	}

	return response;
}
 
開發者ID:krevelen,項目名稱:coala,代碼行數:35,代碼來源:DealOAuth1Util.java

示例2: recursiveGCSSync

import com.google.api.client.http.InputStreamContent; //導入依賴的package包/類
private void recursiveGCSSync(File repo, String prefix, Storage gcs) throws IOException {
  for (String name : repo.list()) {
    if (!name.equals(".git")) {
      File file = new File(repo.getPath(), name);
      if (file.isDirectory()) {
        recursiveGCSSync(file, prefix + file.getName() + "/", gcs);
      } else {
        InputStream inputStream = new FileInputStream(repo.getPath() + "/" + file.getName());
        InputStreamContent mediaContent = new InputStreamContent("text/plain", inputStream);
        mediaContent.setLength(file.length());
        StorageObject objectMetadata = new StorageObject()
            .setName(prefix + file.getName());
        gcs.objects().insert(bucket, objectMetadata, mediaContent).execute();
      }
    }
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:policyscanner,代碼行數:18,代碼來源:GitGCSSyncApp.java

示例3: uploadFile

import com.google.api.client.http.InputStreamContent; //導入依賴的package包/類
/**
 * Uploads data to an object in a bucket.
 *
 * @param name the name of the destination object.
 * @param contentType the MIME type of the data.
 * @param file the file to upload.
 * @param bucketName the name of the bucket to create the object in.
 */
private void uploadFile(String name, String contentType, File file, String bucketName) throws IOException,
        GeneralSecurityException {
    InputStreamContent contentStream = new InputStreamContent(contentType, new FileInputStream(file));
    // Setting the length improves upload performance
    contentStream.setLength(file.length());
    StorageObject objectMetadata = new StorageObject()
            // Set the destination object name
            .setName(name)
            // Set the access control list to publicly read-only
            .setAcl(Arrays.asList(
                    new ObjectAccessControl().setEntity("allUsers").setRole("READER")));

    // Do the insert
    Storage client = StorageFactory.getService();
    Storage.Objects.Insert insertRequest = client.objects().insert(
            bucketName, objectMetadata, contentStream);

    insertRequest.execute();
    LogUtils.debug(LOG_TAG, "Successfully uploaded file to bucket.\nName: " + name + "\nBucket name: " +
            bucketName);
}
 
開發者ID:darshanmaiya,項目名稱:MCSFS,代碼行數:30,代碼來源:GCStore.java

示例4: uploadCache

import com.google.api.client.http.InputStreamContent; //導入依賴的package包/類
@Override
public void uploadCache(JobOutputProcessor outputProcessor, String cachePath) {
    try {
            outputProcessor.output("Uploading cache file " + cacheFileName + " to google storage\n");

            Storage client = createClient();
            File uploadFile = new File(cachePath);
            InputStreamContent contentStream = new InputStreamContent(
                    null, new FileInputStream(uploadFile));
            contentStream.setLength(uploadFile.length());
            StorageObject objectMetadata = new StorageObject()
                    .setName(cacheFileName);

            Storage.Objects.Insert insertRequest = client.objects().insert(
                    settings.bucketName, objectMetadata, contentStream);

            insertRequest.execute();

            outputProcessor.output("Cache uploaded\n");
    } catch (GeneralSecurityException | IOException e) {
        outputProcessor.output("Error upload cache: " + e.getMessage() + "\n");
    }
}
 
開發者ID:simpleci,項目名稱:simpleci,代碼行數:24,代碼來源:GoogleStorageCacheManager.java

示例5: putBytes

import com.google.api.client.http.InputStreamContent; //導入依賴的package包/類
/** Upload data. */
public static boolean putBytes(final String bucket, final String key, final byte[] bytes) {
    final InputStreamContent mediaContent =
        new InputStreamContent("application/octet-stream", new ByteArrayInputStream(bytes));
    mediaContent.setLength(bytes.length);

    try {
        final Storage.Objects.Insert insertObject =
            client.objects().insert(bucket, null, mediaContent);
        insertObject.setName(key);
        if (mediaContent.getLength() > 0
            && mediaContent.getLength() <= 2 * 1000 * 1000 /* 2MB */) {
            insertObject.getMediaHttpUploader().setDirectUploadEnabled(true);
        }
        insertObject.execute();
        return true;
    } catch (IOException e) {
        LOGGER.error("Error uploading data", e);
        return false;
    }
}
 
開發者ID:DevOps-TangoMe,項目名稱:gcloud-storage-speedtest,代碼行數:22,代碼來源:StorageManager.java

示例6: saveImage

import com.google.api.client.http.InputStreamContent; //導入依賴的package包/類
/**
 * Method to insert a image into the bucket of the cloud storage.
 *
 * @author <a href="mailto:[email protected]"> João Felipe de Medeiros Moreira </a>
 * @since 15/10/2015
 *
 * @param name of the image.
 * @param contentStream to be converted.
 *
 * @return the media link of the image.
 *
 * @throws IOException in case a IO problem.
 * @throws GeneralSecurityException in case a security problem.
 */
public static String saveImage(String name, InputStreamContent contentStream)
    throws IOException, GeneralSecurityException {
  logger.finest("###### Saving a image");
  StorageObject objectMetadata = new StorageObject()
      // Set the destination object name
      .setName(name)
      // Set the access control list to publicly read-only
      .setAcl(Arrays.asList(new ObjectAccessControl().setEntity(ALL_USERS).setRole(READER)));

  Storage client = getService();
  String bucketName = getBucket().getName();
  Storage.Objects.Insert insertRequest =
      client.objects().insert(bucketName, objectMetadata, contentStream);

  return insertRequest.execute().getMediaLink();
}
 
開發者ID:ciandt-dev,項目名稱:tech-gallery,代碼行數:31,代碼來源:StorageHandler.java

示例7: uploadFile

import com.google.api.client.http.InputStreamContent; //導入依賴的package包/類
/**
 * Uploads data to an object in a bucket.
 *
 * @param name the name of the destination object.
 * @param contentType the MIME type of the data.
 * @param file the file to upload.
 * @param bucketName the name of the bucket to create the object in.
 */
public static void uploadFile(
    String name, String contentType, File file, String bucketName)
    throws IOException, GeneralSecurityException {
  InputStreamContent contentStream = new InputStreamContent(
      contentType, new FileInputStream(file));
  // Setting the length improves upload performance
  contentStream.setLength(file.length());
  StorageObject objectMetadata = new StorageObject()
      // Set the destination object name
      .setName(name)
      // Set the access control list to publicly read-only
      .setAcl(Arrays.asList(
          new ObjectAccessControl().setEntity("allUsers").setRole("READER")));

  // Do the insert
  Storage client = StorageFactory.getService();
  Storage.Objects.Insert insertRequest = client.objects().insert(
      bucketName, objectMetadata, contentStream);

  insertRequest.execute();
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:30,代碼來源:StorageSample.java

示例8: createRequest

import com.google.api.client.http.InputStreamContent; //導入依賴的package包/類
@Override
public Insert createRequest(InputStreamContent inputStream) throws IOException {
  // Create object with the given name and metadata.
  StorageObject object =
      new StorageObject()
          .setMetadata(metadata)
          .setName(objectName);

  Insert insert = gcs.objects().insert(bucketName, object, inputStream);
  writeConditions.apply(insert);
  if (insert.getMediaHttpUploader() != null) {
    insert.getMediaHttpUploader().setDirectUploadEnabled(isDirectUploadEnabled());
    insert.getMediaHttpUploader().setProgressListener(
      new LoggingMediaHttpUploaderProgressListener(this.objectName, MIN_LOGGING_INTERVAL_MS));
  }
  insert.setName(objectName);
  return insert;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:bigdata-interop,代碼行數:19,代碼來源:GoogleCloudStorageWriteChannel.java

示例9: uploadFile

import com.google.api.client.http.InputStreamContent; //導入依賴的package包/類
public static com.google.api.services.drive.model.File uploadFile(
        java.io.File file, Credential credential, String parent)
        throws IOException {
    com.google.api.services.drive.model.File fileMetadata = new com.google.api.services.drive.model.File();
    fileMetadata.setParents(Arrays.asList(new ParentReference()
            .setId(parent)));
    fileMetadata.setTitle(file.getName());
    InputStreamContent mediaContent = new InputStreamContent(
            "image/png", new BufferedInputStream(new FileInputStream(
                    file)));
    mediaContent.setLength(file.length());

    Drive.Files.Insert insert = drive.files().insert(fileMetadata,
            mediaContent);
    MediaHttpUploader uploader = insert.getMediaHttpUploader();
    uploader.setDirectUploadEnabled(true);
    return insert.execute();
}
 
開發者ID:mba811,項目名稱:loli.io,代碼行數:19,代碼來源:GDriveAPI.java

示例10: createFile

import com.google.api.client.http.InputStreamContent; //導入依賴的package包/類
public File createFile(File file, InputStream content) throws IOException {

        logger.debug("creating {}", file);

        com.google.api.services.drive.model.File gdFile = file.toGdFile();

        Drive.Files.Insert request;
        if (file.isDirectory()) {
            request = drive.files().insert(gdFile);
        } else {
            request = drive.files().insert(gdFile, new InputStreamContent(file.getMimeType(), content));
            request.getMediaHttpUploader().setDirectUploadEnabled(true);
        }

        return new File(request.execute());
    }
 
開發者ID:stepank,項目名稱:jdbox,代碼行數:17,代碼來源:DriveAdapter.java

示例11: uploadFile

import com.google.api.client.http.InputStreamContent; //導入依賴的package包/類
public File uploadFile(String name, String mimeType, java.io.File mediaFile, boolean onWifi)
		throws IOException, JSONException {
	// File Metadata
	File fileMetadata = new File();
	fileMetadata.setTitle(name);
	fileMetadata.setMimeType(mimeType);

	// Set the parent folder.
	ParentReference uploadDir = new ParentReference();
	uploadDir.setId(findUploadDirectory().getId());
	fileMetadata.setParents(Arrays.asList(uploadDir));

	InputStreamContent mediaContent = new InputStreamContent(mimeType, new BufferedInputStream(
			new FileInputStream(mediaFile)));
	mediaContent.setLength(mediaFile.length());

	Drive.Files.Insert insert = drive.files().insert(fileMetadata, mediaContent);
	insert.getMediaHttpUploader().setProgressListener(new ProgressListener(mediaFile));
	insert.getMediaHttpUploader().setBackOffPolicyEnabled(true);
	int chunkSize = onWifi ? MediaHttpUploader.MINIMUM_CHUNK_SIZE * 2
			: MediaHttpUploader.MINIMUM_CHUNK_SIZE;
	insert.getMediaHttpUploader().setChunkSize(chunkSize);
	return insert.execute();

}
 
開發者ID:DarrenMowat,項目名稱:PicSync,代碼行數:26,代碼來源:DriveApi.java

示例12: upload

import com.google.api.client.http.InputStreamContent; //導入依賴的package包/類
@Override
public void upload(final File thumbnail, final String videoid, final Account account) throws FileNotFoundException, ThumbnailIOException {
	if (!thumbnail.exists()) {
		throw new FileNotFoundException(thumbnail.getName());
	}

	final YouTube youTube = youTubeProvider.setAccount(account).get();
	try (final BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(thumbnail))) {

		youTube.thumbnails()
				.set(videoid, new InputStreamContent("application/octet-stream", bufferedInputStream))
				.execute();
	} catch (final IOException e) {
		throw new ThumbnailIOException(e);
	}
}
 
開發者ID:dennisfischer,項目名稱:simplejavayoutubeuploader,代碼行數:17,代碼來源:ThumbnailServiceImpl.java

示例13: writeBlob

import com.google.api.client.http.InputStreamContent; //導入依賴的package包/類
/**
 * Writes a blob in the bucket.
 *
 * @param inputStream content of the blob to be written
 * @param blobSize    expected size of the blob to be written
 */
void writeBlob(String blobName, InputStream inputStream, long blobSize) throws IOException {
    SocketAccess.doPrivilegedVoidIOException(() -> {
        InputStreamContent stream = new InputStreamContent(null, inputStream);
        stream.setLength(blobSize);

        Storage.Objects.Insert insert = client.objects().insert(bucket, null, stream);
        insert.setName(blobName);
        insert.execute();
    });
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:GoogleCloudStorageBlobStore.java

示例14: exportOnline

import com.google.api.client.http.InputStreamContent; //導入依賴的package包/類
/**
 * Backup database to google docs
 * 
 * @param drive Google docs connection
 * @param targetFolder Google docs folder name
 * */
public String exportOnline(Drive drive, String targetFolder) throws Exception {
	// get folder first
       String folderId = GoogleDriveClient.getOrCreateDriveFolder(drive, targetFolder);
	if (folderId == null) {
           throw new ImportExportException(R.string.gdocs_folder_not_found);
	}

	// generation backup file
	String fileName = generateFilename();
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
       OutputStream out = new BufferedOutputStream(new GZIPOutputStream(outputStream));
	generateBackup(out);

	// transforming streams
	InputStream backup = new ByteArrayInputStream(outputStream.toByteArray());

       InputStreamContent mediaContent = new InputStreamContent(BACKUP_MIME_TYPE, new  BufferedInputStream(backup));
       mediaContent.setLength(outputStream.size());
       // File's metadata.
       com.google.api.services.drive.model.File body = new com.google.api.services.drive.model.File();
       body.setTitle(fileName);
       body.setMimeType(BACKUP_MIME_TYPE);
       body.setFileSize((long)outputStream.size());
       List<ParentReference> parentReference = new ArrayList<ParentReference>();
       parentReference.add(new ParentReference().setId(folderId)) ;
       body.setParents(parentReference);
       com.google.api.services.drive.model.File file = drive.files().insert(body, mediaContent).execute();

	return fileName;
}
 
開發者ID:tiberiusteng,項目名稱:financisto1-holo,代碼行數:37,代碼來源:Export.java

示例15: getStagedURI

import com.google.api.client.http.InputStreamContent; //導入依賴的package包/類
private String getStagedURI(Cluster cluster, String uri) {
  URI parsed = URI.create(uri);

  if (!isNullOrEmpty(parsed.getScheme()) && !"file".equals(parsed.getScheme())) {
    return uri;
  }

  // either a file URI or just a path, stage it to GCS
  File local = Paths.get(uri).toFile();
  String configBucket = cluster.getConfig().getConfigBucket();

  LOG.debug("Staging {} in GCS bucket {}", uri, configBucket);

  try {
    InputStreamContent content = new InputStreamContent(
        "application/octet-stream", new FileInputStream(local));
    content.setLength(local.length()); // docs say that setting length improves upload perf

    StorageObject object = new StorageObject()
        .setName(Paths.get(GCS_STAGING_PREFIX, local.getName()).toString());

    object = client.storage().objects()
        .insert(configBucket, object, content)
        .execute();
    return new URI("gs", object.getBucket(), "/" + object.getName(), null).toString();
  } catch (URISyntaxException | IOException e) {
    throw Throwables.propagate(e);
  }
}
 
開發者ID:spotify,項目名稱:dataproc-java-submitter,代碼行數:30,代碼來源:Jobs.java


注:本文中的com.google.api.client.http.InputStreamContent類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。