Java Code Examples for com.google.common.io.Resources#asByteSource()

The following examples show how to use com.google.common.io.Resources#asByteSource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExampleRecordSet.java    From presto with Apache License 2.0 6 votes vote down vote up
public ExampleRecordSet(ExampleSplit split, List<ExampleColumnHandle> columnHandles)
{
    requireNonNull(split, "split is null");

    this.columnHandles = requireNonNull(columnHandles, "column handles is null");
    ImmutableList.Builder<Type> types = ImmutableList.builder();
    for (ExampleColumnHandle column : columnHandles) {
        types.add(column.getColumnType());
    }
    this.columnTypes = types.build();

    try {
        byteSource = Resources.asByteSource(split.getUri().toURL());
    }
    catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
}
 
Example 2
Source File: DockerConfig.java    From doclipser with Eclipse Public License 1.0 6 votes vote down vote up
private Properties readPropertyFile(URL url) {
    final ByteSource byteSource = Resources.asByteSource(url);
    final Properties properties = new Properties();
    InputStream inputStream = null;
    try {
        inputStream = byteSource.openBufferedStream();
        properties.load(inputStream);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (final IOException ioException) {
                ioException.printStackTrace();
            }
        }
    }
    return properties;
}
 
Example 3
Source File: DockerClientFactory.java    From doclipser with Eclipse Public License 1.0 6 votes vote down vote up
private static String getDockerClientClassName() {
    final URL url = Resources.getResource(Constants.PROPERTY_FILE_NAME);
    final ByteSource byteSource = Resources.asByteSource(url);
    final Properties properties = new Properties();
    InputStream inputStream = null;
    try {
        inputStream = byteSource.openBufferedStream();
        properties.load(inputStream);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (final IOException ioException) {
                ioException.printStackTrace();
            }
        }
    }
    return properties.getProperty(Constants.PROPERTY_DOCKER_CLIENT_LIB);
}
 
Example 4
Source File: UrlResource.java    From purplejs with Apache License 2.0 4 votes vote down vote up
@Override
public ByteSource getBytes()
{
    return Resources.asByteSource( this.url );
}
 
Example 5
Source File: EmbeddedResource.java    From dropwizard-debpkg-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public ByteSource getSource() {
    return Resources.asByteSource(resource);
}
 
Example 6
Source File: ArrayByteSourceTest.java    From Strata with Apache License 2.0 4 votes vote down vote up
@Test
public void test_from_GuavaUrlByteSource() throws MalformedURLException {
  ByteSource source = Resources.asByteSource(new File("pom.xml").toURI().toURL());
  ArrayByteSource test = ArrayByteSource.from(source);
  assertThat(test.getFileName()).hasValue("pom.xml");
}
 
Example 7
Source File: UrlDownloaderService.java    From estatio with Apache License 2.0 4 votes vote down vote up
@Override
public byte[] download(final URL url) throws IOException {
    final ByteSource byteSource = Resources.asByteSource(url);
    return byteSource.read();
}
 
Example 8
Source File: DefaultDocTemplate.java    From js-dossier with Apache License 2.0 4 votes vote down vote up
private static TemplateFile loadResourceFile(String name, String path) {
  URL url = DefaultDocTemplate.class.getResource(path);
  checkNotNull(url, "Resource not found: %s", path);
  return new TemplateFile(Resources.asByteSource(url), name);
}
 
Example 9
Source File: ReportDownloader.java    From googleads-java-lib with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a CharSource of report contents with {@code ReportDownloadOptions}. The ExportFormat
 * must be string-based, such as {@link
 * com.google.api.ads.admanager.jaxws.v201908.ExportFormat#CSV_DUMP}.
 *
 * @param options the options to download the report with
 * @return a new CharSource of report results
 * @throws IOException if there was an error performing any I/O action, including any SOAP calls
 * @throws ApiException_Exception if there was any problem making the SOAP call
 * @throws IllegalStateException if the report is not ready to be downloaded
 * @throws IllegalArgumentException if the {@link ExportFormat} is not a string-based format
 */
public CharSource getReportAsCharSource(ReportDownloadOptions options)
    throws IOException, ApiException_Exception {
  Preconditions.checkArgument(
      SUPPORTED_CHARSOUCE_EXPORT_FORMATS.contains(options.getExportFormat()),
      "ExportFormat " + options.getExportFormat() + " cannot be used with CharSource");
  ByteSource byteSource = Resources.asByteSource(getDownloadUrl(options));
  return (options.isUseGzipCompression() ? new GZippedByteSource(byteSource) : byteSource)
      .asCharSource(REPORT_CHARSET);
}
 
Example 10
Source File: ReportDownloader.java    From googleads-java-lib with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a CharSource of report contents with {@code ReportDownloadOptions}. The ExportFormat
 * must be string-based, such as {@link
 * com.google.api.ads.admanager.axis.v202005.ExportFormat#CSV_DUMP}.
 *
 * @param options the options to download the report with
 * @return a new CharSource of report results
 * @throws IOException if there was an error performing any I/O action, including any SOAP calls
 * @throws IllegalStateException if the report is not ready to be downloaded
 * @throws IllegalArgumentException if the {@link ExportFormat} is not a string-based format
 */
public CharSource getReportAsCharSource(ReportDownloadOptions options) throws IOException {
  Preconditions.checkArgument(
      SUPPORTED_CHARSOURCE_EXPORT_FORMATS.contains(options.getExportFormat()),
      "ExportFormat " + options.getExportFormat() + " cannot be used with CharSource");
  ByteSource byteSource = Resources.asByteSource(getDownloadUrl(options));
  return (options.getUseGzipCompression() ? new GZippedByteSource(byteSource) : byteSource)
      .asCharSource(REPORT_CHARSET);
}
 
Example 11
Source File: ReportDownloader.java    From googleads-java-lib with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a CharSource of report contents with {@code ReportDownloadOptions}. The ExportFormat
 * must be string-based, such as {@link
 * com.google.api.ads.admanager.axis.v201911.ExportFormat#CSV_DUMP}.
 *
 * @param options the options to download the report with
 * @return a new CharSource of report results
 * @throws IOException if there was an error performing any I/O action, including any SOAP calls
 * @throws IllegalStateException if the report is not ready to be downloaded
 * @throws IllegalArgumentException if the {@link ExportFormat} is not a string-based format
 */
public CharSource getReportAsCharSource(ReportDownloadOptions options) throws IOException {
  Preconditions.checkArgument(
      SUPPORTED_CHARSOURCE_EXPORT_FORMATS.contains(options.getExportFormat()),
      "ExportFormat " + options.getExportFormat() + " cannot be used with CharSource");
  ByteSource byteSource = Resources.asByteSource(getDownloadUrl(options));
  return (options.getUseGzipCompression() ? new GZippedByteSource(byteSource) : byteSource)
      .asCharSource(REPORT_CHARSET);
}
 
Example 12
Source File: ReportDownloader.java    From googleads-java-lib with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a CharSource of report contents with {@code ReportDownloadOptions}. The ExportFormat
 * must be string-based, such as {@link
 * com.google.api.ads.admanager.axis.v202002.ExportFormat#CSV_DUMP}.
 *
 * @param options the options to download the report with
 * @return a new CharSource of report results
 * @throws IOException if there was an error performing any I/O action, including any SOAP calls
 * @throws IllegalStateException if the report is not ready to be downloaded
 * @throws IllegalArgumentException if the {@link ExportFormat} is not a string-based format
 */
public CharSource getReportAsCharSource(ReportDownloadOptions options) throws IOException {
  Preconditions.checkArgument(
      SUPPORTED_CHARSOURCE_EXPORT_FORMATS.contains(options.getExportFormat()),
      "ExportFormat " + options.getExportFormat() + " cannot be used with CharSource");
  ByteSource byteSource = Resources.asByteSource(getDownloadUrl(options));
  return (options.getUseGzipCompression() ? new GZippedByteSource(byteSource) : byteSource)
      .asCharSource(REPORT_CHARSET);
}
 
Example 13
Source File: ReportDownloader.java    From googleads-java-lib with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a CharSource of report contents with {@code ReportDownloadOptions}. The ExportFormat
 * must be string-based, such as {@link
 * com.google.api.ads.admanager.axis.v201908.ExportFormat#CSV_DUMP}.
 *
 * @param options the options to download the report with
 * @return a new CharSource of report results
 * @throws IOException if there was an error performing any I/O action, including any SOAP calls
 * @throws IllegalStateException if the report is not ready to be downloaded
 * @throws IllegalArgumentException if the {@link ExportFormat} is not a string-based format
 */
public CharSource getReportAsCharSource(ReportDownloadOptions options) throws IOException {
  Preconditions.checkArgument(
      SUPPORTED_CHARSOURCE_EXPORT_FORMATS.contains(options.getExportFormat()),
      "ExportFormat " + options.getExportFormat() + " cannot be used with CharSource");
  ByteSource byteSource = Resources.asByteSource(getDownloadUrl(options));
  return (options.getUseGzipCompression() ? new GZippedByteSource(byteSource) : byteSource)
      .asCharSource(REPORT_CHARSET);
}
 
Example 14
Source File: ReportDownloader.java    From googleads-java-lib with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a CharSource of report contents with {@code ReportDownloadOptions}. The ExportFormat
 * must be string-based, such as {@link
 * com.google.api.ads.admanager.jaxws.v202002.ExportFormat#CSV_DUMP}.
 *
 * @param options the options to download the report with
 * @return a new CharSource of report results
 * @throws IOException if there was an error performing any I/O action, including any SOAP calls
 * @throws ApiException_Exception if there was any problem making the SOAP call
 * @throws IllegalStateException if the report is not ready to be downloaded
 * @throws IllegalArgumentException if the {@link ExportFormat} is not a string-based format
 */
public CharSource getReportAsCharSource(ReportDownloadOptions options)
    throws IOException, ApiException_Exception {
  Preconditions.checkArgument(
      SUPPORTED_CHARSOUCE_EXPORT_FORMATS.contains(options.getExportFormat()),
      "ExportFormat " + options.getExportFormat() + " cannot be used with CharSource");
  ByteSource byteSource = Resources.asByteSource(getDownloadUrl(options));
  return (options.isUseGzipCompression() ? new GZippedByteSource(byteSource) : byteSource)
      .asCharSource(REPORT_CHARSET);
}
 
Example 15
Source File: ReportDownloader.java    From googleads-java-lib with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a CharSource of report contents with {@code ReportDownloadOptions}. The ExportFormat
 * must be string-based, such as {@link
 * com.google.api.ads.admanager.jaxws.v201911.ExportFormat#CSV_DUMP}.
 *
 * @param options the options to download the report with
 * @return a new CharSource of report results
 * @throws IOException if there was an error performing any I/O action, including any SOAP calls
 * @throws ApiException_Exception if there was any problem making the SOAP call
 * @throws IllegalStateException if the report is not ready to be downloaded
 * @throws IllegalArgumentException if the {@link ExportFormat} is not a string-based format
 */
public CharSource getReportAsCharSource(ReportDownloadOptions options)
    throws IOException, ApiException_Exception {
  Preconditions.checkArgument(
      SUPPORTED_CHARSOUCE_EXPORT_FORMATS.contains(options.getExportFormat()),
      "ExportFormat " + options.getExportFormat() + " cannot be used with CharSource");
  ByteSource byteSource = Resources.asByteSource(getDownloadUrl(options));
  return (options.isUseGzipCompression() ? new GZippedByteSource(byteSource) : byteSource)
      .asCharSource(REPORT_CHARSET);
}
 
Example 16
Source File: ClassPath.java    From codebuff with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Returns a {@link ByteSource} view of the resource from which its bytes can be read.
 *
 * @throws NoSuchElementException if the resource cannot be loaded through the class loader,
 *     despite physically existing in the class path.
 * @since 20.0
 */
public final ByteSource asByteSource() {
  return Resources.asByteSource(url());
}
 
Example 17
Source File: ClassPath.java    From codebuff with BSD 2-Clause "Simplified" License votes vote down vote up
/**
 * Returns a {@link ByteSource} view of the resource from which its bytes can be read.
 *
 * @throws NoSuchElementException if the resource cannot be loaded through the class loader,
 *     despite physically existing in the class path.
 * @since 20.0
 */


public final ByteSource asByteSource() {
  return Resources.asByteSource(url());
}
 
Example 18
Source File: ClassPath.java    From codebuff with BSD 2-Clause "Simplified" License votes vote down vote up
/**
 * Returns a {@link ByteSource} view of the resource from which its bytes can be read.
 *
 * @throws NoSuchElementException if the resource cannot be loaded through the class loader,
 *     despite physically existing in the class path.
 * @since 20.0
 */


public final ByteSource asByteSource() {
  return Resources.asByteSource(url());
}
 
Example 19
Source File: ClassPath.java    From codebuff with BSD 2-Clause "Simplified" License votes vote down vote up
/**
 * Returns a {@link ByteSource} view of the resource from which its bytes can be read.
 *
 * @throws NoSuchElementException if the resource cannot be loaded through the class loader,
 *     despite physically existing in the class path.
 * @since 20.0
 */


public final ByteSource asByteSource() {
  return Resources.asByteSource(url());
}
 
Example 20
Source File: ClassPath.java    From codebuff with BSD 2-Clause "Simplified" License votes vote down vote up
/**
 * Returns a {@link ByteSource} view of the resource from which its bytes can be read.
 *
 * @throws NoSuchElementException if the resource cannot be loaded through the class loader,
 *     despite physically existing in the class path.
 * @since 20.0
 */


public final ByteSource asByteSource() {
  return Resources.asByteSource(url());
}