Skip to content
This repository was archived by the owner on Feb 18, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions storage-cmdline-sample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/*
11 changes: 6 additions & 5 deletions storage-cmdline-sample/instructions.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ <h3>Browse Online</h3>

<ul>
<li><a
href="http://code.google.com/p/google-api-java-client/source/browse?repo=samples#hg/storage-cmdline-sample">Browse
href="https://github.com/google/google-api-java-client-samples/tree/master/storage-cmdline-sample">Browse
Source</a>, or main file <a
href="http://code.google.com/p/google-api-java-client/source/browse/storage-cmdline-sample/src/main/java/com/google/api/services/samples/storage/cmdline/StorageSample.java?repo=samples">StorageSample.java</a></li>
href="https://github.com/google/google-api-java-client-samples/blob/master/storage-cmdline-sample/src/main/java/com/google/api/services/samples/storage/cmdline/StorageSample.java">StorageSample.java</a></li>
</ul>

<h3>Register Your Application</h3>

<ul>
<li>Visit the <a href="https://cloud.google.com/console/start/api?id=storage_api">Google Developers Console</a>.
<li>Visit the <a href="https://console.developers.google.com/flows/enableapi?apiid=storage_api">Google Developers Console</a>.
</li>
<li>If necessary, sign in to your Google Account, select or create a project,
and agree to the terms of service. Click Continue.</li>
Expand All @@ -30,7 +30,8 @@ <h3>Register Your Application</h3>
</li>
</ul>
<p>For more information about registering your application, see the Google Cloud Storage documentation
<a href="https://developers.google.com/storage/docs/json_api/v1/json-api-java-samples">JSON Java Example</a>.
<a href="https://developers.google.com/storage/docs/json_api/v1/json-api-java-samples">JSON Java Example</a>,
as setup for that simpler example is similar.
</p>
<h3>Checkout Instructions</h3>

Expand All @@ -45,7 +46,7 @@ <h3>Checkout Instructions</h3>

<pre>
cd <i>[someDirectory]</i>
hg clone https://code.google.com/p/google-api-java-client.samples/ google-api-java-client-samples
git clone https://github.com/google/google-api-java-client-samples.git
cd google-api-java-client-samples/storage-cmdline-sample
cp ~/Downloads/client_secrets.json src/main/resources/client_secrets.json
# Edit the settings file and enter in appropriate values.
Expand Down
18 changes: 9 additions & 9 deletions storage-cmdline-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@


<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>${project.api.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>14.0.1</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-jetty</artifactId>
Expand All @@ -98,7 +98,7 @@
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-storage</artifactId>
<version>v1beta2-rev51-1.19.0</version>
<version>v1-rev33-1.20.0</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
Expand All @@ -109,9 +109,9 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.http.version>1.19.0</project.http.version>
<project.oauth.version>1.19.0</project.oauth.version>
<project.api.version>1.19.0</project.api.version>
<project.http.version>1.20.0</project.http.version>
<project.oauth.version>1.20.0</project.oauth.version>
<project.api.version>1.20.0</project.api.version>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package com.google.api.services.samples.storage.cmdline;

import java.io.InputStream;
import java.util.Random;


/**
* Support classes for the command-line sample.
*/
public class Helpers {

/**
* Generates a random data block and repeats it to provide the stream.
*
* <p>Using a buffer instead of just filling from java.util.Random because the latter causes
* noticeable lag in stream reading, which detracts from upload speed. This class takes all that
* cost in the constructor.
*/
public static class RandomDataBlockInputStream extends InputStream {

private long byteCountRemaining;
private final byte[] buffer;

public RandomDataBlockInputStream(long size, int blockSize) {
byteCountRemaining = size;
final Random random = new Random();
buffer = new byte[blockSize];
random.nextBytes(buffer);
}

/*
* (non-Javadoc)
*
* @see java.io.InputStream#read()
*/
@Override
public int read() {
throw new AssertionError("Not implemented; too slow.");
}

/*
* (non-Javadoc)
*
* @see java.io.InputStream#read(byte [], int, int)
*/
@Override
public int read(byte b[], int off, int len) {
if (b == null) {
throw new NullPointerException();
} else if (off < 0 || len < 0 || len > b.length - off) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
} else if (byteCountRemaining == 0) {
return -1;
}
int actualLen = len > byteCountRemaining ? (int) byteCountRemaining : len;
for (int i = off; i < actualLen; i++) {
b[i] = buffer[i % buffer.length];
}
byteCountRemaining -= actualLen;
return actualLen;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package com.google.api.services.samples.storage.cmdline;

import com.google.api.client.json.GenericJson;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.util.Key;

import java.io.IOException;

/** Samples settings JSON Model. */
public final class SampleSettings extends GenericJson {

@Key("project")
private String project;

@Key("bucket")
private String bucket;

@Key("prefix")
private String prefix;

public String getProject() {
return project;
}

public String getBucket() {
return bucket;
}

public String getPrefix() {
return prefix;
}

public static SampleSettings load(JsonFactory jsonFactory) throws IOException {
try {
return jsonFactory.fromInputStream(
StorageSample.class.getResourceAsStream("/sample_settings.json"), SampleSettings.class);
} catch (IOException e) {
IOException e2 = new IOException("Unable to read sample_settings.json: " + e.getMessage(), e);
throw e2;
}
}
}

Loading