当前位置: 首页>>代码示例>>Java>>正文


Java GcsFileOptions类代码示例

本文整理汇总了Java中com.google.appengine.tools.cloudstorage.GcsFileOptions的典型用法代码示例。如果您正苦于以下问题:Java GcsFileOptions类的具体用法?Java GcsFileOptions怎么用?Java GcsFileOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GcsFileOptions类属于com.google.appengine.tools.cloudstorage包,在下文中一共展示了GcsFileOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createOrUpdate

import com.google.appengine.tools.cloudstorage.GcsFileOptions; //导入依赖的package包/类
/**
 * Create or update a file in a GCC bucket, using the default ACL for the bucket.
 *
 * @param filename Name of file to create
 * @param contents File contents
 * @param shortCache If true, sets cache expiry to 0 sec. Otherwise, cache expiry is set to 6,000 sec.
 * @throws IOException
 */
public void createOrUpdate(String filename, JsonElement contents, boolean shortCache)
    throws IOException {
  GcsFilename file = new GcsFilename(defaultBucket, filename);
  GcsFileOptions options = new GcsFileOptions.Builder()
    .mimeType("application/json")
    .cacheControl("public, max-age="+(shortCache?0:6000))
    .build();
  GcsOutputChannel writeChannel = null;
  try {
    writeChannel = gcsService.createOrReplace(file, options);
    Writer writer = Channels.newWriter(writeChannel, DEFAULT_CHARSET_NAME);
    new Gson().toJson(contents, writer);
    writer.flush();
  } finally {
    if (writeChannel != null) {
      writeChannel.close();
    }
  }
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:28,代码来源:CloudFileManager.java

示例2: createRawFile

import com.google.appengine.tools.cloudstorage.GcsFileOptions; //导入依赖的package包/类
private FileData createRawFile(Key<ProjectData> projectKey, FileData.RoleEnum role,
  String userId, String fileName, byte[] content) throws ObjectifyException, IOException {
  validateGCS();
  FileData file = new FileData();
  file.fileName = fileName;
  file.projectKey = projectKey;
  file.role = role;
  file.userId = userId;
  if (useGCSforFile(fileName, content.length)) {
    file.isGCS = true;
    file.gcsName = makeGCSfileName(fileName, projectKey.getId());
    GcsOutputChannel outputChannel =
      gcsService.createOrReplace(new GcsFilename(GCS_BUCKET_NAME, file.gcsName), GcsFileOptions.getDefaultInstance());
    outputChannel.write(ByteBuffer.wrap(content));
    outputChannel.close();
  } else {
    file.content = content;
  }
  return file;
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:21,代码来源:ObjectifyStorageIo.java

示例3: saveDiffFile

import com.google.appengine.tools.cloudstorage.GcsFileOptions; //导入依赖的package包/类
private Iterable<ImmutableObject> saveDiffFile(
    CommitLogCheckpoint checkpoint, ImmutableObject... entities) throws IOException {
  DateTime now = checkpoint.getCheckpointTime();
  List<ImmutableObject> allEntities = Lists.asList(checkpoint, entities);
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  for (ImmutableObject entity : allEntities) {
    serializeEntity(entity, output);
  }
  gcsService.createOrReplace(
      new GcsFilename(GCS_BUCKET, DIFF_FILE_PREFIX + now),
      new GcsFileOptions.Builder()
          .addUserMetadata(LOWER_BOUND_CHECKPOINT, now.minusMinutes(1).toString())
          .build(),
      ByteBuffer.wrap(output.toByteArray()));
  return allEntities;
}
 
开发者ID:google,项目名称:nomulus,代码行数:17,代码来源:RestoreCommitLogsActionTest.java

示例4: setUp

import com.google.appengine.tools.cloudstorage.GcsFileOptions; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  action.driveConnection = driveConnection;
  action.gcsUtils = gcsUtils;

  when(driveConnection.createFile(
      anyString(), any(MediaType.class), anyString(), any(byte[].class)))
          .thenReturn("drive-id-123");

  persistResource(loadRegistrar("TheRegistrar").asBuilder().setDriveFolderId("0B-12345").build());

  // Persist an empty GCS file to the local GCS service so that failure tests won't fail
  // prematurely on the file not existing.
  gcsService.createOrReplace(
      new GcsFilename("mah-buckit", "some/folder/detail_report.csv"),
      GcsFileOptions.getDefaultInstance(),
      ByteBuffer.allocate(0));
}
 
开发者ID:google,项目名称:nomulus,代码行数:19,代码来源:PublishDetailReportActionTest.java

示例5: testSuccess

import com.google.appengine.tools.cloudstorage.GcsFileOptions; //导入依赖的package包/类
@Test
public void testSuccess() throws Exception {
  // Create a dummy file in the local GCS service to read in the servlet.
  gcsService.createOrReplace(
      new GcsFilename("mah-buckit", "some/folder/detail_report.csv"),
      GcsFileOptions.getDefaultInstance(),
      ByteBuffer.wrap("one,two,three\n".getBytes(UTF_8)));

  Map<String, Object> response =
      action.handleJsonRequest(ImmutableMap.of(
          REGISTRAR_ID_PARAM, "TheRegistrar",
          GCS_BUCKET_PARAM, "mah-buckit",
          GCS_FOLDER_PREFIX_PARAM, "some/folder/",
          DETAIL_REPORT_NAME_PARAM, "detail_report.csv"));

  verify(driveConnection).createFile(
      "detail_report.csv", MediaType.CSV_UTF_8, "0B-12345", "one,two,three\n".getBytes(UTF_8));
  assertThat(response).containsEntry("driveId", "drive-id-123");
}
 
开发者ID:google,项目名称:nomulus,代码行数:20,代码来源:PublishDetailReportActionTest.java

示例6: write

import com.google.appengine.tools.cloudstorage.GcsFileOptions; //导入依赖的package包/类
private static void write(final String stringFileName, final String value, final String contentType)  {
    try {
        final GcsFileOptions options = new GcsFileOptions.Builder()
                .mimeType(contentType)
                .acl("public-read")
                .build();

        final GcsOutputChannel writeChannel = gcsService.createOrReplace(open(stringFileName), options);
        final PrintWriter writer = new PrintWriter(Channels.newWriter(writeChannel, "UTF-8"));
        writer.print(value);
        writer.flush();
        writeChannel.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:RCasatta,项目名称:op_return,代码行数:17,代码来源:GCSService.java

示例7: createOrUpdate

import com.google.appengine.tools.cloudstorage.GcsFileOptions; //导入依赖的package包/类
public void createOrUpdate(String filename, JsonElement contents, boolean shortCache)
    throws IOException {
  GcsFilename file = new GcsFilename(defaultBucket, filename);
  GcsFileOptions options = new GcsFileOptions.Builder()
    .mimeType("application/json")
    .acl("public-read")
    .cacheControl("public, max-age="+(shortCache?0:6000))
    .build();
  GcsOutputChannel writeChannel = null;
  try {
    writeChannel = gcsService.createOrReplace(file, options);
    Writer writer = Channels.newWriter(writeChannel, DEFAULT_CHARSET_NAME);
    new Gson().toJson(contents, writer);
    writer.flush();
  } finally {
    if (writeChannel != null) {
      writeChannel.close();
    }
  }
}
 
开发者ID:The-WebOps-Club,项目名称:saarang-iosched,代码行数:21,代码来源:CloudFileManager.java

示例8: save

import com.google.appengine.tools.cloudstorage.GcsFileOptions; //导入依赖的package包/类
public static void save (byte[] data, Supplier<String> mime, String path) {
	if (LOG.isLoggable(Level.FINER)) {
		LOG.finer("Saving data with mime type [" + mime + "] to [" + path
				+ "]");
	}

	GcsFileOptions instance = new GcsFileOptions.Builder()
			.mimeType(mime.get()).build();
	GcsFilename fileName = new GcsFilename(
			System.getProperty(BUCKET_NAME_PROPERTY_KEY), path);

	try (BufferedOutputStream osw = new BufferedOutputStream(
			Channels.newOutputStream(GcsServiceFactory.createGcsService()
					.createOrReplace(fileName, instance)))) {
		osw.write(data);
	} catch (IOException e) {
		LOG.log(Level.SEVERE,
				"Error occured trying to write data to [" + path + "]", e);
	}
}
 
开发者ID:billy1380,项目名称:blogwt,代码行数:21,代码来源:GcsHelper.java

示例9: composeObject

import com.google.appengine.tools.cloudstorage.GcsFileOptions; //导入依赖的package包/类
@Override
public void composeObject(Iterable<String> source, GcsFilename dest, long timeoutMillis)
    throws IOException {
  ensureInitialized();
  int size = Iterables.size(source);
  if (size > 32) {
    throw new IOException("Compose attempted with too many components. Limit is 32");
  }
  if (size < 2) {
    throw new IOException("You must provide at least two source components.");
  }
  Token token = beginObjectCreation(dest, GcsFileOptions.getDefaultInstance(), timeoutMillis);

  for (String filename : source) {
    GcsFilename sourceGcsFilename = new GcsFilename(dest.getBucketName(), filename);
    appendFileContentsToToken(sourceGcsFilename, token);
  }
  finishObjectCreation(token, ByteBuffer.allocate(0), timeoutMillis);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-gcs-client,代码行数:20,代码来源:LocalRawGcsService.java

示例10: copyObject

import com.google.appengine.tools.cloudstorage.GcsFileOptions; //导入依赖的package包/类
@Override
public void copyObject(GcsFilename source, GcsFilename dest, GcsFileOptions fileOptions,
    long timeoutMillis) throws IOException {
  ensureInitialized();
  GcsFileMetadata meta = getObjectMetadata(source, timeoutMillis);
  if (meta == null) {
    throw new FileNotFoundException(this + ": No such file: " + source);
  }
  if (fileOptions == null) {
    fileOptions = meta.getOptions();
  }

  Token token = beginObjectCreation(dest, fileOptions, timeoutMillis);
  appendFileContentsToToken(source, token);
  finishObjectCreation(token, ByteBuffer.allocate(0), timeoutMillis);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-gcs-client,代码行数:17,代码来源:LocalRawGcsService.java

示例11: beginObjectCreation

import com.google.appengine.tools.cloudstorage.GcsFileOptions; //导入依赖的package包/类
@Override
public RawGcsCreationToken beginObjectCreation(
    GcsFilename filename, GcsFileOptions options, long timeoutMillis) throws IOException {
  HTTPRequest req = makeRequest(filename, null, POST, timeoutMillis);
  req.setHeader(RESUMABLE_HEADER);
  addOptionsHeaders(req, options);
  HTTPResponse resp;
  try {
    resp = urlfetch.fetch(req);
  } catch (IOException e) {
    throw createIOException(new HTTPRequestInfo(req), e);
  }
  if (resp.getResponseCode() == 201) {
    String location = URLFetchUtils.getSingleHeader(resp, LOCATION);
    String queryString = new URL(location).getQuery();
    Preconditions.checkState(
        queryString != null, LOCATION + " header," + location + ", witout a query string");
    Map<String, String> params = Splitter.on('&').withKeyValueSeparator('=').split(queryString);
    Preconditions.checkState(params.containsKey(UPLOAD_ID),
        LOCATION + " header," + location + ", has a query string without " + UPLOAD_ID);
    return new GcsRestCreationToken(filename, params.get(UPLOAD_ID), 0);
  } else {
    throw HttpErrorHandler.error(new HTTPRequestInfo(req), resp);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-gcs-client,代码行数:26,代码来源:OauthRawGcsService.java

示例12: addOptionsHeaders

import com.google.appengine.tools.cloudstorage.GcsFileOptions; //导入依赖的package包/类
private void addOptionsHeaders(HTTPRequest req, GcsFileOptions options) {
  if (options == null) {
    return;
  }
  if (options.getMimeType() != null) {
    req.setHeader(new HTTPHeader(CONTENT_TYPE, options.getMimeType()));
  }
  if (options.getAcl() != null) {
    req.setHeader(new HTTPHeader(ACL, options.getAcl()));
  }
  if (options.getCacheControl() != null) {
    req.setHeader(new HTTPHeader(CACHE_CONTROL, options.getCacheControl()));
  }
  if (options.getContentDisposition() != null) {
    req.setHeader(new HTTPHeader(CONTENT_DISPOSITION, options.getContentDisposition()));
  }
  if (options.getContentEncoding() != null) {
    req.setHeader(new HTTPHeader(CONTENT_ENCODING, options.getContentEncoding()));
  }
  for (Entry<String, String> entry : options.getUserMetadata().entrySet()) {
    req.setHeader(new HTTPHeader(X_GOOG_META + entry.getKey(), entry.getValue()));
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-gcs-client,代码行数:24,代码来源:OauthRawGcsService.java

示例13: copyObject

import com.google.appengine.tools.cloudstorage.GcsFileOptions; //导入依赖的package包/类
@Override
public void copyObject(GcsFilename source, GcsFilename dest, GcsFileOptions fileOptions,
    long timeoutMillis) throws IOException {
  HTTPRequest req = makeRequest(dest, null, PUT, timeoutMillis);
  req.setHeader(new HTTPHeader(X_GOOG_COPY_SOURCE, makePath(source)));
  if (fileOptions != null) {
    req.setHeader(REPLACE_METADATA_HEADER);
    addOptionsHeaders(req, fileOptions);
  }
  HTTPResponse resp;
  try {
    resp = urlfetch.fetch(req);
  } catch (IOException e) {
    throw createIOException(new HTTPRequestInfo(req), e);
  }
  if (resp.getResponseCode() != 200) {
    throw HttpErrorHandler.error(new HTTPRequestInfo(req), resp);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-gcs-client,代码行数:20,代码来源:OauthRawGcsService.java

示例14: testCreateGsBlobKey

import com.google.appengine.tools.cloudstorage.GcsFileOptions; //导入依赖的package包/类
@Test
@InSequence(100)
public void testCreateGsBlobKey() throws Exception {
    final long ts = System.currentTimeMillis();
    final byte[] bytes = "FooBar".getBytes();

    GcsService service = GcsServiceFactory.createGcsService();
    GcsFilename filename = new GcsFilename("GcsBucket", String.valueOf(ts));
    GcsFileOptions options = new GcsFileOptions.Builder().mimeType(CONTENT_TYPE).build();
    try (GcsOutputChannel out = service.createOrReplace(filename, options)) {
        IOUtils.copy(Channels.newChannel(new ByteArrayInputStream(bytes)), out);
    }

    BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
    BlobKey key =  blobstoreService.createGsBlobKey("/gs/GcsBucket/" + ts);
    byte[] fetched = blobstoreService.fetchData(key, 0, 10);
    Assert.assertArrayEquals(bytes, fetched);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:19,代码来源:GcsBlobstoreUploadTest.java

示例15: testCreateGsObj

import com.google.appengine.tools.cloudstorage.GcsFileOptions; //导入依赖的package包/类
@Test
@InSequence(1)
public void testCreateGsObj() throws IOException {
    GcsFilename filename = new GcsFilename(bucket, OBJECT_NAME);
    GcsFileOptions option = new GcsFileOptions.Builder()
        .mimeType("text/html")
        .acl("public-read")
        .build();

    try (GcsOutputChannel writeChannel = gcsService.createOrReplace(filename, option)) {
        PrintWriter out = new PrintWriter(Channels.newWriter(writeChannel, "UTF8"));
        out.println(CONTENT);
        out.flush();

        writeChannel.waitForOutstandingWrites();
        writeChannel.write(ByteBuffer.wrap(MORE_WORDS.getBytes()));
        assertEquals(filename, writeChannel.getFilename());
    }

    assertEquals(bucket, filename.getBucketName());
    assertEquals(OBJECT_NAME, filename.getObjectName());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:23,代码来源:GCSClientTest.java


注:本文中的com.google.appengine.tools.cloudstorage.GcsFileOptions类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。