Package com.fasterxml.storemate.shared.compress

Examples of com.fasterxml.storemate.shared.compress.Compression


            InputStream in = conn.getInputStream();
            // Then, anything to uncompress?
            String comps = conn.getHeaderField(ClusterMateConstants.HTTP_HEADER_COMPRESSION);
            if (comps != null && !comps.isEmpty()) {
                Compression comp = Compression.from(comps);
                if (comp != null) {
                    in = Compressors.uncompressingStream(in, comp);
                }
            }
            Handler<T> h = processor.createHandler();
View Full Code Here


        path = _keyConverter.appendToPath(path, contentId);      
        if (params != null) {
            path = params.appendToPath(path, contentId);
        }
        // Is compression known?
        Compression comp = content.getExistingCompression();
        if (comp != null) { // if so, must be indicated
            path = path.setHeader(ClusterMateConstants.HTTP_HEADER_COMPRESSION, comp.asContentEncoding());
        }
        Generator<K> gen = new Generator<K>(content, _keyConverter);
        int checksum = gen.getChecksum();
        path = path.addParameter(ClusterMateConstants.QUERY_PARAM_CHECKSUM,
                (checksum == 0) ? "0" : String.valueOf(checksum));
View Full Code Here

        FluentCaseInsensitiveStringsMap headers = (h == null) ? null : h.getHeaders();
        _headers = headers;
        String comps = (headers == null) ? null : headers.getFirstValue(ClusterMateConstants.HTTP_HEADER_COMPRESSION);
        if (comps != null && !comps.isEmpty()) {
            Uncompressor uncomp = null;
            Compression c = Compression.from(comps);
            if (c == Compression.LZF) {
                uncomp = new LZFUncompressor(this);
            } else if (c == Compression.GZIP) {
                uncomp = new GZIPUncompressor(this);
            } else if (c == Compression.NONE) {
View Full Code Here

        final long accessTime = _timeMaster.currentTimeMillis();
        final E entry = _entryConverter.entryFromStorable(rawEntry);

        updateLastAccessedForGet(request, response, entry, accessTime);
       
        Compression comp = entry.getCompression();
        boolean skipCompression;

        // Range to resolve, now that we know full length?
        if (range != null) {
            range = range.resolveWithTotalLength(entry.getActualUncompressedLength());
            final long length = range.calculateLength();
            // any bytes matching? If not, it's a failure
            if (length <= 0L) {
                return response.badRange(new GetErrorResponse<K>(key, "Invalid 'Range' HTTP Header (\""+range+"\")"));
            }
            // note: can not skip decompress if we have to give range...
            skipCompression = false;
        } else {
            skipCompression = (comp != Compression.NONE) && comp.isAcceptable(acceptableEnc);
        }
       
        StreamingResponseContent output;

        if (entry.hasExternalData()) { // need to stream from File
            File f = entry.getRaw().getExternalFile(_fileManager);
            // this is where we can expect to get "file not found exception".
            // NOTE: not optimal, since this is one I/O operation that is outside throttling;
            // but that can't be helped for now -- we MUST catch the problem here, before
            // adding other response information
            try {
                output = new FileBackedResponseContentImpl(diag, _timeMaster, _stores.getEntryStore(),
                    accessTime, f, skipCompression ? null : comp, range, entry);
            } catch (StoreException e) {
                LOG.error("Problem trying to GET entry '"+key+"': "+e.getMessage());
                return response.internalFileNotFound(new GetErrorResponse<K>(key, e.getMessage()));
            }
        } else { // inline
            ByteContainer inlined = entry.getRaw().getInlinedData();
            if (!skipCompression) {
                try {
                    inlined = Compressors.uncompress(inlined, comp, (int) entry.getRaw().getOriginalLength());
                } catch (IOException e) {
                    return internalGetError(response, e, key, "Failed to decompress inline data");
                }
            }
            output = new SimpleStreamingResponseContent(diag, _timeMaster, inlined, range, inlined.byteLength());
        }
        long cl = output.getLength();
        if (cl >= 0L) {
            response = response.setContentLength(cl);
        }
        // add header for range if necessary; also, response code differs
        if (range == null) {
            response = response.ok(output);
        } else {
            response = response.partialContent(output, range.asResponseHeader());
        }
        // Need to provide Etag, if content hash available
        int contentHash = rawEntry.getContentHash();
        if (contentHash != HashConstants.NO_CHECKSUM) {
            StringBuilder sb = new StringBuilder();
            sb.append('"');
            sb.append(contentHash);
            sb.append('"');
            response = response.addHeader(ClusterMateConstants.HTTP_HEADER_ETAG, sb.toString());
        }
        // also need to let client know we left compression in there:
        if (skipCompression) {
            response = response.setBodyCompression(comp.asContentEncoding());
        }
        return response;
    }
View Full Code Here

        final E entry = _entryConverter.entryFromStorable(rawEntry);
        // should this be recorded in OpStats?
        updateLastAccessedForHead(request, response, entry, accessTime);
       
        // Other than this: let's only check out length of data there would be...
        final Compression comp = entry.getCompression();
        long size;
       
        // Would we return content as-is? (not compressed, or compressed using something
        // client accepts)
        String acceptableComp = request.getHeader(ClusterMateConstants.HTTP_HEADER_ACCEPT_COMPRESSION);
        if ((comp == Compression.NONE) ||
                (acceptableComp != null && !acceptableComp.isEmpty() && comp.isAcceptable(acceptableComp))) {
            size = entry.getStorageLength();
        } else {
            size = entry.getActualUncompressedLength();
        }
        return response.ok().setContentLength(size);
View Full Code Here

            OperationDiagnostics stats)
    {
        final long  creationTime = _timeMaster.currentTimeMillis();

        // What compression, if any, is payload using?
        Compression inputCompression = Compression.forContentEncoding(request.getHeader(
                ClusterMateConstants.HTTP_HEADER_COMPRESSION));
        final StorableCreationMetadata stdMetadata = new StorableCreationMetadata(inputCompression,
                checksum, 0);
        if (inputCompression != null && inputCompression != Compression.NONE) {
            String valueStr = request.getHeader(ClusterMateConstants.CUSTOM_HTTP_HEADER_UNCOMPRESSED_LENGTH);
View Full Code Here

        }
        if (oldEntry.getCompressedHash() != newEntry.compressedContentHash) {
            return "checksumForCompressed differ; old had 0x"+Integer.toHexString(oldEntry.getCompressedHash())
                    +", new 0x"+Integer.toHexString(newEntry.compressedContentHash);
        }
        Compression oldC = oldEntry.getCompression();
        Compression newC = newEntry.compression;
        if (newC == null) {
            newC = Compression.NONE;
        }
        if (oldC != newC) {
            return "entity compression differs; old had "+oldC+" new "+newC;
View Full Code Here

    protected ListItem defaultMinimalListItemFromStorable(Storable raw) {
        return new ListItem(raw.getKey(), raw.getContentHash(), raw.getActualUncompressedLength());
    }

    protected ItemInfo defaultItemInfoFromStorable(Storable raw) {
        Compression c = raw.getCompression();
        Character compression = (c == null || c == Compression.NONE) ? null
                : Character.valueOf(c.asChar());
        long compLen = (compression == null) ? -1L : raw.getStorageLength();
        StringBuilder sb = new StringBuilder(4);
        if (raw.isDeleted()) {
            sb.append(ItemInfo.FLAG_DELETED);
        }
View Full Code Here

        FluentCaseInsensitiveStringsMap headers = (h == null) ? null : h.getHeaders();
        _headers = headers;
        String comps = (headers == null) ? null : headers.getFirstValue(ClusterMateConstants.HTTP_HEADER_COMPRESSION);
        if (comps != null && !comps.isEmpty()) {
            Uncompressor uncomp = null;
            Compression c = Compression.from(comps);
            if (c == Compression.LZF) {
                uncomp = new LZFUncompressor(this);
            } else if (c == Compression.GZIP) {
                uncomp = new GZIPUncompressor(this);
            } else if (c == Compression.NONE) {
View Full Code Here

        JdkHttpClientPathBuilder path = _server.rootPath();
        path = _pathFinder.appendStoreEntryPath(path);
        path = _keyConverter.appendToPath(path, contentId);

        // Is compression known?
        Compression comp = content.getExistingCompression();
        if (comp != null) { // if so, must be indicated
            path = path.addCompression(comp, content.uncompressedLength());
        }
        path = path.setContentType(ClusterMateConstants.HTTP_CONTENT_BINARY);
        if (params != null) {
View Full Code Here

TOP

Related Classes of com.fasterxml.storemate.shared.compress.Compression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.