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


Java AbstractInputStreamContent类代码示例

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


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

示例1: testConflictExceptionOnCreate

import com.google.api.client.http.AbstractInputStreamContent; //导入依赖的package包/类
/**
 * Tests the write method of BigQueryRecordWriter without writing anything but throwing a 409
 * conflict from the job-insertion.
 */
@Test
public void testConflictExceptionOnCreate() throws IOException, GeneralSecurityException {
  IOException fakeConflictException = new IOException("fake 409 conflict");
  when(mockInsert.execute())
      .thenThrow(fakeConflictException);
  when(mockErrorExtractor.itemAlreadyExists(any(IOException.class)))
      .thenReturn(true);

  initializeRecordWriter();

  // Close the RecordWriter.
  recordWriter.close(mockContext);

  // Check that the proper calls were sent to the BigQuery.
  verify(mockFactory).getBigQueryHelper(any(Configuration.class));
  verify(mockBigQuery, times(2)).jobs();
  verify(mockJobsGet, times(1)).execute();
  verify(mockBigQueryJobs, times(1)).get(eq(jobProjectId), eq(jobReference.getJobId()));
  verify(mockBigQueryJobs).insert(
      eq(jobProjectId), eq(getExpectedJob()), any(AbstractInputStreamContent.class));
  assertTrue(executorService.isShutdown());
}
 
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:27,代码来源:BigQueryRecordWriterTest.java

示例2: testUnhandledExceptionOnCreate

import com.google.api.client.http.AbstractInputStreamContent; //导入依赖的package包/类
/**
 * Tests the write method of BigQueryRecordWriter without writing anything but throwing an
 * unhandled exeption from the job-insertion.
 */
@Test
public void testUnhandledExceptionOnCreate() throws IOException, GeneralSecurityException {
  IOException fakeUnhandledException = new IOException("fake unhandled exception");
  when(mockInsert.execute())
      .thenThrow(fakeUnhandledException);
  when(mockErrorExtractor.itemAlreadyExists(any(IOException.class)))
      .thenReturn(false);

  initializeRecordWriter();

  // Close the RecordWriter; the stored exception finally propagates out.
  try {
    recordWriter.close(mockContext);
    fail("Expected IOException on close, got no exception.");
  } catch (IOException ioe) {
    assertEquals(fakeUnhandledException, ioe.getCause());
  }

  // Check that the proper calls were sent to the BigQuery.
  verify(mockFactory).getBigQueryHelper(any(Configuration.class));
  verify(mockBigQuery, times(1)).jobs();
  verify(mockBigQueryJobs).insert(
      eq(jobProjectId), eq(getExpectedJob()), any(AbstractInputStreamContent.class));
  assertTrue(executorService.isShutdown());
}
 
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:30,代码来源:BigQueryRecordWriterTest.java

示例3: testCreateEmptyObject

import com.google.api.client.http.AbstractInputStreamContent; //导入依赖的package包/类
/**
 * Test successful operation of GoogleCloudStorage.createEmptyObject(1).
 */
@Test
public void testCreateEmptyObject()
    throws IOException {
  when(mockStorage.objects()).thenReturn(mockStorageObjects);
  when(mockStorageObjects.insert(
      eq(BUCKET_NAME), any(StorageObject.class), any(AbstractInputStreamContent.class)))
      .thenReturn(mockStorageObjectsInsert);

  gcs.createEmptyObject(new StorageResourceId(BUCKET_NAME, OBJECT_NAME));
  verify(mockStorage).objects();
  ArgumentCaptor<StorageObject> storageObjectCaptor =
      ArgumentCaptor.forClass(StorageObject.class);
  ArgumentCaptor<AbstractInputStreamContent> inputStreamCaptor =
      ArgumentCaptor.forClass(AbstractInputStreamContent.class);
  verify(mockStorageObjects).insert(
      eq(BUCKET_NAME), storageObjectCaptor.capture(), inputStreamCaptor.capture());
  verify(mockStorageObjectsInsert).setDisableGZipContent(eq(true));
  verify(mockClientRequestHelper).setDirectUploadEnabled(eq(mockStorageObjectsInsert), eq(true));
  verify(mockStorageObjectsInsert).execute();

  assertEquals(OBJECT_NAME, storageObjectCaptor.getValue().getName());
  assertEquals(0, inputStreamCaptor.getValue().getLength());
}
 
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:27,代码来源:GoogleCloudStorageTest.java

示例4: testIgnoreExceptionsOnCreateEmptyObjects

import com.google.api.client.http.AbstractInputStreamContent; //导入依赖的package包/类
@Test
public void testIgnoreExceptionsOnCreateEmptyObjects() throws IOException {
  when(mockStorage.objects()).thenReturn(mockStorageObjects);
  when(mockStorageObjects.insert(
      eq(BUCKET_NAME), any(StorageObject.class), any(AbstractInputStreamContent.class)))
      .thenReturn(mockStorageObjectsInsert);
  when(mockStorageObjectsInsert.execute())
      .thenThrow(new IOException("rateLimitExceeded"));
  when(mockErrorExtractor.rateLimited(any(IOException.class))).thenReturn(true);
  when(mockStorageObjects.get(eq(BUCKET_NAME), eq(OBJECT_NAME)))
      .thenReturn(mockStorageObjectsGet);
  when(mockStorageObjectsGet.execute())
      .thenReturn(getStorageObjectForEmptyObjectWithMetadata(EMPTY_METADATA));

  gcs.createEmptyObjects(ImmutableList.of(new StorageResourceId(BUCKET_NAME, OBJECT_NAME)));

  verify(mockStorage, times(2)).objects();
  verify(mockStorageObjects).insert(
      eq(BUCKET_NAME), any(StorageObject.class), any(AbstractInputStreamContent.class));
  verify(mockStorageObjectsInsert).setDisableGZipContent(eq(true));
  verify(mockClientRequestHelper).setDirectUploadEnabled(eq(mockStorageObjectsInsert), eq(true));
  verify(mockStorageObjectsInsert).execute();
  verify(mockErrorExtractor).rateLimited(any(IOException.class));
  verify(mockStorageObjects).get(eq(BUCKET_NAME), eq(OBJECT_NAME));
  verify(mockStorageObjectsGet).execute();
}
 
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:27,代码来源:GoogleCloudStorageTest.java

示例5: testIgnoreExceptionsOnCreateEmptyObjectsNonIgnorableException

import com.google.api.client.http.AbstractInputStreamContent; //导入依赖的package包/类
@Test
public void testIgnoreExceptionsOnCreateEmptyObjectsNonIgnorableException() throws IOException {
  when(mockStorage.objects()).thenReturn(mockStorageObjects);
  when(mockStorageObjects.insert(
      eq(BUCKET_NAME), any(StorageObject.class), any(AbstractInputStreamContent.class)))
      .thenReturn(mockStorageObjectsInsert);
  when(mockStorageObjectsInsert.execute())
      .thenThrow(new IOException("forbidden"));
  when(mockErrorExtractor.rateLimited(any(IOException.class))).thenReturn(false);
  when(mockErrorExtractor.isInternalServerError(any(IOException.class))).thenReturn(false);

  expectedException.expect(IOException.class);
  try {
    gcs.createEmptyObjects(ImmutableList.of(new StorageResourceId(BUCKET_NAME, OBJECT_NAME)));
  } finally {
    verify(mockStorage).objects();
    verify(mockStorageObjects).insert(
        eq(BUCKET_NAME), any(StorageObject.class), any(AbstractInputStreamContent.class));
    verify(mockStorageObjectsInsert).setDisableGZipContent(eq(true));
    verify(mockClientRequestHelper).setDirectUploadEnabled(
        eq(mockStorageObjectsInsert), eq(true));
    verify(mockStorageObjectsInsert).execute();
    verify(mockErrorExtractor).rateLimited(any(IOException.class));
    verify(mockErrorExtractor).isInternalServerError(any(IOException.class));
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:27,代码来源:GoogleCloudStorageTest.java

示例6: createTimeLineItemWithAtachement

import com.google.api.client.http.AbstractInputStreamContent; //导入依赖的package包/类
/**
 * The real Mirror API supports Multipart-bodies to attach images to cards, Emulator not, we will transformt the
 * card in one HTML TimeLineItem. https://github.com/Scarygami/mirror-api - REAMDME.md
 * 
 * @param content The initial timeline item.
 * @param mediaContent The attachement image.
 * @return The initial timeline item modified to look like one HTML card with the atachement.
 * @throws IOException
 * @throws FileNotFoundException
 */

public static TimelineItem createTimeLineItemWithAtachement(TimelineItem content,
        AbstractInputStreamContent mediaContent) throws IOException, FileNotFoundException {

    // We are going to transform the card in one HTML card.
    if (content.getHtml() != null && content.getHtml().isEmpty()) {
        // If the card already contains html then we do nothing
        LOG.log(Level.WARNING,
                "Emulation limitation : Images are transformes in HTML card, you must choose, or HTML or Attachement. your attachement will be ignored. ");
    } else {
        // Store the image
        String attachementURL = storeAttachement(mediaContent);

        // Transform card in one HTML card
        String cardText = content.getText() != null ? content.getText() : "";
        String html = "<article class=\"photo\">  <img src="
                + attachementURL
                + " width=\"100%\" height=\"100%\">  <div class=\"photo-overlay\"></div>  <section>    <p class=\"text-auto-size\">"
                + cardText + "</p>  </section></article>";
        content.setHtml(html);
    }
    return content;
}
 
开发者ID:MarcosBermudez,项目名称:java-mirror-api-emulator,代码行数:34,代码来源:EmulatorUtil.java

示例7: storeAttachement

import com.google.api.client.http.AbstractInputStreamContent; //导入依赖的package包/类
/**
 * Transform attachement in one local URL
 * 
 * @param mediaContent the attachement to transform into URL
 * @return The attachement return URL
 * @throws IOException
 * @throws FileNotFoundException
 */
public static String storeAttachement(com.google.api.client.http.AbstractInputStreamContent mediaContent)
        throws IOException, FileNotFoundException {

    // Write the file content
    File file = File.createTempFile("img", ".tmp");
    FileOutputStream os = new FileOutputStream(file);
    mediaContent.writeTo(os);
    os.close();
    String filename = file.getName();
    file.deleteOnExit();

    // Write the media type
    if (mediaContent.getType() != null) {
        File fileContentType = new File(file.getPath() + ".contenttype");
        FileWriter fileWriter = new FileWriter(fileContentType, false);
        BufferedWriter bw = new BufferedWriter(fileWriter);
        bw.write(mediaContent.getType());
        bw.close();
        fileContentType.deleteOnExit();
    }

    String imgSrc = "\"" + glasswareHost + "/attachements/" + filename + "\"";
    return imgSrc;
}
 
开发者ID:MarcosBermudez,项目名称:java-mirror-api-emulator,代码行数:33,代码来源:EmulatorUtil.java

示例8: snapshotUserTable

import com.google.api.client.http.AbstractInputStreamContent; //导入依赖的package包/类
public void snapshotUserTable() throws IOException {
    DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
    String timestamp = formatter.print(DateTime.now());
    Table patientTable = new Table()
            .setName("User Profile Data " + timestamp)
            .setDescription("Locations of patients and volunteers as of " + timestamp)
            .setIsExportable(true)
            .setColumns(Arrays.asList(
                    new Column().setName("User Type").setType("STRING"),
                    new Column().setName("Location").setType("LOCATION")
            ));

    patientTable = fusiontables.table().insert(patientTable).execute();

    FusionTableContentWriter fusionTableWriter = new FusionTableContentWriter(patientTable);

    for (UserProfile userProfile : UserProfile.listAll()) {
        fusionTableWriter.writeRecord(userProfile.getType().name(), userProfile.getLocation());
    }

    AbstractInputStreamContent streamContent = fusionTableWriter.getInputStreamContent();
    fusiontables.table().importRows(patientTable.getTableId(), streamContent).execute();

    File patientFile = findFileByTitle(patientTable.getName());
    addToFolder(patientFile);
}
 
开发者ID:openmash,项目名称:mashmesh,代码行数:27,代码来源:DriveExporter.java

示例9: exportRideRecords

import com.google.api.client.http.AbstractInputStreamContent; //导入依赖的package包/类
private void exportRideRecords(Table rideTable, Collection<RideRecord> rideRecords) throws IOException {
    FusionTableContentWriter fusionTableWriter = new FusionTableContentWriter(rideTable);

    for (RideRecord rideRecord : rideRecords) {
        fusionTableWriter.writeRecord(
                rideRecord.getVolunteerLocation(),
                rideRecord.getDepartureTime(),
                rideRecord.getPatientLocation(),
                rideRecord.getPickupTime(),
                rideRecord.getAppointmentAddress(),
                rideRecord.getAppointmentLocation(),
                rideRecord.getAppointmentTime(),
                rideRecord.getDistanceMiles(),
                rideRecord.getTripMinutes()
        );
    }

    AbstractInputStreamContent streamContent = fusionTableWriter.getInputStreamContent();
    fusiontables.table().importRows(rideTable.getTableId(), streamContent).execute();
}
 
开发者ID:openmash,项目名称:mashmesh,代码行数:21,代码来源:DriveExporter.java

示例10: launchJob

import com.google.api.client.http.AbstractInputStreamContent; //导入依赖的package包/类
/**
 * Launch a job, but do not wait for it to complete.
 *
 * @throws BigqueryJobFailureException
 */
private Job launchJob(Job job, @Nullable AbstractInputStreamContent data) {
  verify(job.getStatus() == null);
  try {
    return data != null
        ? bigquery.jobs().insert(getProjectId(), job, data).execute()
        : bigquery.jobs().insert(getProjectId(), job).execute();
  } catch (IOException e) {
    throw BigqueryJobFailureException.create(e);
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:16,代码来源:BigqueryConnection.java

示例11: runJobToCompletion

import com.google.api.client.http.AbstractInputStreamContent; //导入依赖的package包/类
/** Runs job and returns a future that yields {@code result} when {@code job} is completed. */
private <T> ListenableFuture<T> runJobToCompletion(
    final Job job,
    final T result,
    @Nullable final AbstractInputStreamContent data) {
  return service.submit(
      () -> {
        runJob(job, data);
        return result;
      });
}
 
开发者ID:google,项目名称:nomulus,代码行数:12,代码来源:BigqueryConnection.java

示例12: putResource

import com.google.api.client.http.AbstractInputStreamContent; //导入依赖的package包/类
public File putResource(GoogleDrivePutParameters parameters) throws IOException {
    String folderId = parameters.getDestinationFolderId();
    File putFile = new File();
    putFile.setParents(Collections.singletonList(folderId));
    Files.List fileRequest = drive.files().list()
            .setQ(format(QUERY_NOTTRASHED_NAME_NOTMIME_INPARENTS, parameters.getResourceName(), MIME_TYPE_FOLDER, folderId));
    LOG.debug("[putResource] `{}` Exists in `{}` ? with `{}`.", parameters.getResourceName(),
            parameters.getDestinationFolderId(), fileRequest.getQ());
    FileList existingFiles = fileRequest.execute();
    if (existingFiles.getFiles().size() > 1) {
        throw new IOException(messages.getMessage("error.file.more.than.one", parameters.getResourceName()));
    }
    if (existingFiles.getFiles().size() == 1) {
        if (!parameters.isOverwriteIfExist()) {
            throw new IOException(messages.getMessage("error.file.already.exist", parameters.getResourceName()));
        }
        LOG.debug("[putResource] {} will be overwritten...", parameters.getResourceName());
        drive.files().delete(existingFiles.getFiles().get(0).getId()).execute();
    }
    putFile.setName(parameters.getResourceName());
    String metadata = "id,parents,name";
    if (!StringUtils.isEmpty(parameters.getFromLocalFilePath())) {
        // Reading content from local fileName
        FileContent fContent = new FileContent(null, new java.io.File(parameters.getFromLocalFilePath()));
        putFile = drive.files().create(putFile, fContent).setFields(metadata).execute();
        //

    } else if (parameters.getFromBytes() != null) {
        AbstractInputStreamContent content = new ByteArrayContent(null, parameters.getFromBytes());
        putFile = drive.files().create(putFile, content).setFields(metadata).execute();
    }
    return putFile;
}
 
开发者ID:Talend,项目名称:components,代码行数:34,代码来源:GoogleDriveUtils.java

示例13: setUp

import com.google.api.client.http.AbstractInputStreamContent; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    super.setUp();

    properties = new GoogleDrivePutProperties("test");
    properties.connection.setupProperties();
    properties.connection.setupLayout();
    properties.schemaMain.setupProperties();
    properties.schemaMain.setupLayout();
    properties.setupProperties();
    properties.setupLayout();
    properties = (GoogleDrivePutProperties) setupConnectionWithAccessToken(properties);
    properties.uploadMode.setValue(UploadMode.UPLOAD_LOCAL_FILE);
    properties.fileName.setValue(FILE_PUT_NAME);
    properties.localFilePath.setValue("c:/Users/undx/brasil.jpg");
    properties.overwrite.setValue(true);
    properties.destinationFolder.setValue("root");

    testRuntime = spy(GoogleDrivePutRuntime.class);
    doReturn(drive).when(testRuntime).getDriveService();

    when(drive.files().list().setQ(anyString()).execute()).thenReturn(emptyFileList);
    //
    File putFile = new File();
    putFile.setId(PUT_FILE_ID);
    putFile.setParents(Collections.singletonList(PUT_FILE_PARENT_ID));
    when(drive.files().create(any(File.class), any(AbstractInputStreamContent.class)).setFields(anyString()).execute())
            .thenReturn(putFile);

}
 
开发者ID:Talend,项目名称:components,代码行数:31,代码来源:GoogleDrivePutRuntimeTest.java

示例14: setUp

import com.google.api.client.http.AbstractInputStreamContent; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    super.setUp();

    properties = new GoogleDrivePutProperties("test");
    properties.connection.setupProperties();
    properties.connection.setupLayout();
    properties.schemaMain.setupProperties();
    properties.schemaMain.setupLayout();
    properties.setupProperties();
    properties.setupLayout();
    properties = (GoogleDrivePutProperties) setupConnectionWithAccessToken(properties);
    properties.uploadMode.setValue(UploadMode.UPLOAD_LOCAL_FILE);
    properties.fileName.setValue("GoogleDrive Put test BR");
    properties.localFilePath.setValue("c:/Users/undx/brasil.jpg");
    properties.overwrite.setValue(true);
    properties.destinationFolder.setValue("root");

    sink.initialize(container, properties);
    wop = (GoogleDriveWriteOperation) sink.createWriteOperation();
    writer = new GoogleDrivePutWriter(wop, properties, container);

    when(drive.files().list().setQ(anyString()).execute()).thenReturn(emptyFileList);
    //
    File putFile = new File();
    putFile.setId(PUT_FILE_ID);
    putFile.setParents(Collections.singletonList(PUT_FILE_PARENT_ID));
    when(drive.files().create(any(File.class), any(AbstractInputStreamContent.class)).setFields(anyString()).execute())
            .thenReturn(putFile);
}
 
开发者ID:Talend,项目名称:components,代码行数:31,代码来源:GoogleDrivePutWriterTest.java

示例15: setUp

import com.google.api.client.http.AbstractInputStreamContent; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    super.setUp();

    properties = new GoogleDrivePutProperties("test");
    properties.connection.setupProperties();
    properties.connection.setupLayout();
    properties.schemaMain.setupProperties();
    properties.schemaMain.setupLayout();
    properties.setupProperties();
    properties.setupLayout();
    properties = (GoogleDrivePutProperties) setupConnectionWithAccessToken(properties);
    properties.uploadMode.setValue(UploadMode.UPLOAD_LOCAL_FILE);
    properties.fileName.setValue(FILE_PUT_NAME);
    properties.localFilePath
            .setValue(Paths.get(getClass().getClassLoader().getResource("service_account.json").toURI()).toString());
    properties.overwrite.setValue(true);
    properties.destinationFolder.setValue("root");

    when(drive.files().list().setQ(anyString()).execute()).thenReturn(emptyFileList);
    //
    File putFile = new File();
    putFile.setId(PUT_FILE_ID);
    putFile.setParents(Collections.singletonList(PUT_FILE_PARENT_ID));
    when(drive.files().create(any(File.class), any(AbstractInputStreamContent.class)).setFields(anyString()).execute())
            .thenReturn(putFile);

}
 
开发者ID:Talend,项目名称:components,代码行数:29,代码来源:GoogleDrivePutReaderTest.java


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