Example usage for com.google.common.net MediaType TAR

List of usage examples for com.google.common.net MediaType TAR

Introduction

In this page you can find the example usage for com.google.common.net MediaType TAR.

Prototype

MediaType TAR

To view the source code for com.google.common.net MediaType TAR.

Click Source Link

Usage

From source file:org.haiku.haikudepotserver.pkg.job.AbstractPkgResourceExportArchiveJobRunner.java

@Override
public void run(JobService jobService, T specification) throws IOException {

    Preconditions.checkArgument(null != jobService);
    Preconditions.checkArgument(null != specification);

    Stopwatch stopwatch = Stopwatch.createStarted();
    final ObjectContext context = serverRuntime.newContext();
    int offset = 0;

    // this will register the outbound data against the job.
    JobDataWithByteSink jobDataWithByteSink = jobService.storeGeneratedData(specification.getGuid(), "download",
            MediaType.TAR.toString());

    try (final OutputStream outputStream = jobDataWithByteSink.getByteSink().openBufferedStream();
            final GZIPOutputStream gzipOutputStream = new GZIPOutputStream(outputStream); // tars assumed to be compressed
            final TarArchiveOutputStream tarOutputStream = new TarArchiveOutputStream(gzipOutputStream)) {

        State state = new State();
        state.tarArchiveOutputStream = tarOutputStream;
        EJBQLQuery query = createEjbqlQuery(specification);
        query.setFetchLimit(getBatchSize());
        int countLastQuery;

        do {//ww  w  . j  a v a2  s .  c o  m
            query.setFetchOffset(offset);
            List<Object[]> queryResults = context.performQuery(query);
            countLastQuery = queryResults.size();
            appendFromRawRows(state, queryResults);
            offset += countLastQuery;

            if (0 == offset % 100) {
                LOGGER.debug("processed {} entries", offset + 1);
            }

        } while (countLastQuery > 0);

        appendArchiveInfo(state);
    }

    LOGGER.info("did produce report for {} entries in {}ms", offset, stopwatch.elapsed(TimeUnit.MILLISECONDS));

}

From source file:org.haiku.haikudepotserver.job.LocalJobServiceImpl.java

@Override
public String deriveDataFilename(String jobDataGuid) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(jobDataGuid));

    String descriptor = "jobdata";
    String extension = "dat";

    Optional<JobData> jobDataOptional = tryGetData(jobDataGuid);

    if (jobDataOptional.isPresent()) {

        JobData jobData = jobDataOptional.get();
        Optional<? extends JobSnapshot> jobOptional = tryGetJobForData(jobDataGuid);

        if (jobOptional.isPresent()) {
            descriptor = jobOptional.get().getJobTypeCode();
        }// w ww . j av a 2 s.c  o  m

        // TODO; get the extensions from a file etc...
        if (!Strings.isNullOrEmpty(jobData.getMediaTypeCode())) {
            if (jobData.getMediaTypeCode().startsWith(MediaType.CSV_UTF_8.withoutParameters().toString())) {
                extension = "csv";
            }

            if (jobData.getMediaTypeCode().equals(MediaType.ZIP.withoutParameters().toString())) {
                extension = "zip";
            }

            if (jobData.getMediaTypeCode().equals(MediaType.TAR.withoutParameters().toString())) {
                extension = "tgz";
            }

            if (jobData.getMediaTypeCode().equals(MediaType.PLAIN_TEXT_UTF_8.withoutParameters().toString())) {
                extension = "txt";
            }
        }
    }

    return String.format("hds_%s_%s_%s.%s", descriptor,
            DateTimeHelper.create14DigitDateTimeFormat().format(Instant.now()), jobDataGuid.substring(0, 4),
            extension);
}