List of usage examples for com.google.api.client.googleapis.media MediaHttpUploader MINIMUM_CHUNK_SIZE
int MINIMUM_CHUNK_SIZE
To view the source code for com.google.api.client.googleapis.media MediaHttpUploader MINIMUM_CHUNK_SIZE.
Click Source Link
From source file:com.google.cloud.hadoop.util.AbstractGoogleAsyncWriteChannel.java
License:Open Source License
/** * Sets size of upload buffer used.//from w w w . j a va2s. c o m */ public void setUploadBufferSize(int bufferSize) { Preconditions.checkArgument(bufferSize > 0, "Upload buffer size must be great than 0."); Preconditions.checkArgument(bufferSize % MediaHttpUploader.MINIMUM_CHUNK_SIZE == 0, "Upload buffer size must be a multiple of MediaHttpUploader.MINIMUM_CHUNK_SIZE"); if ((bufferSize > GCS_UPLOAD_GRANULARITY) && (bufferSize % GCS_UPLOAD_GRANULARITY != 0)) { LOG.warn("Upload buffer size should be a multiple of {} for best performance, got {}", GCS_UPLOAD_GRANULARITY, bufferSize); } uploadBufferSize = bufferSize; }
From source file:com.wiwit.eplweb.util.youtube.api.VideoService.java
License:Apache License
public static void doChangeThumbnail(String videoId, InputStream imageStream) { // This OAuth 2.0 access scope allows for full read/write access to the // authenticated user's account. List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube"); try {/* w w w .j a v a2s.c o m*/ // Authorize the request. Credential credential = Auth.authorize(scopes, "youtube"); // This object is used to make YouTube Data API requests. youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential) .setApplicationName("eplweb").build(); // Create an object that contains the thumbnail image file's // contents. InputStreamContent mediaContent = new InputStreamContent(IMAGE_FILE_FORMAT, imageStream); // Create an API request that specifies that the mediaContent // object is the thumbnail of the specified video. Set thumbnailSet = youtube.thumbnails().set(videoId, mediaContent); // Set the upload type and add an event listener. MediaHttpUploader uploader = thumbnailSet.getMediaHttpUploader(); // Indicate whether direct media upload is enabled. A value of // "True" indicates that direct media upload is enabled and that // the entire media content will be uploaded in a single request. // A value of "False," which is the default, indicates that the // request will use the resumable media upload protocol, which // supports the ability to resume an upload operation after a // network interruption or other transmission failure, saving // time and bandwidth in the event of network failures. uploader.setDirectUploadEnabled(false); uploader.setChunkSize(MediaHttpUploader.MINIMUM_CHUNK_SIZE); // Set the upload state for the thumbnail image. MediaHttpUploaderProgressListener progressListener = new MediaHttpUploaderProgressListener() { @Override public void progressChanged(MediaHttpUploader uploader) throws IOException { switch (uploader.getUploadState()) { case INITIATION_STARTED: logger.info("INITIATION_STARTED"); break; case INITIATION_COMPLETE: logger.info("INITIATION_COMPLETE"); break; case MEDIA_IN_PROGRESS: logger.info("MEDIA_IN_PROGRESS : " + uploader.getProgress()); break; case MEDIA_COMPLETE: logger.info("MEDIA_COMPLETE"); break; case NOT_STARTED: logger.info("NOT_STARTED"); break; } } }; uploader.setProgressListener(progressListener); // Upload the image and set it as the specified video's thumbnail. thumbnailSet.execute(); } catch (GoogleJsonResponseException e) { logger.info("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); e.printStackTrace(); } catch (IOException e) { logger.info("IOException: " + e.getMessage()); e.printStackTrace(); } catch (Throwable t) { logger.error("Throwable: " + t.getMessage()); t.printStackTrace(); } }
From source file:org.blom.martin.stream2gdrive.Stream2GDrive.java
License:Apache License
private static int calcChunkSize(float chunkSizeInMiB) { int multiple = Math.round(chunkSizeInMiB * 1024 * 1024 / MediaHttpUploader.MINIMUM_CHUNK_SIZE); return Math.max(1, multiple) * MediaHttpUploader.MINIMUM_CHUNK_SIZE; }