| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| CdOcket |
|
| 1.0;1 | ||||
| CdOcket$AjcClosure1 |
|
| 1.0;1 | ||||
| CdOcket$AjcClosure11 |
|
| 1.0;1 | ||||
| CdOcket$AjcClosure13 |
|
| 1.0;1 | ||||
| CdOcket$AjcClosure15 |
|
| 1.0;1 | ||||
| CdOcket$AjcClosure17 |
|
| 1.0;1 | ||||
| CdOcket$AjcClosure3 |
|
| 1.0;1 | ||||
| CdOcket$AjcClosure5 |
|
| 1.0;1 | ||||
| CdOcket$AjcClosure7 |
|
| 1.0;1 | ||||
| CdOcket$AjcClosure9 |
|
| 1.0;1 |
| 1 | 0 | /** |
| 2 | * Copyright (c) 2012-2015, jcabi.com | |
| 3 | * All rights reserved. | |
| 4 | * | |
| 5 | * Redistribution and use in source and binary forms, with or without | |
| 6 | * modification, are permitted provided that the following conditions | |
| 7 | * are met: 1) Redistributions of source code must retain the above | |
| 8 | * copyright notice, this list of conditions and the following | |
| 9 | * disclaimer. 2) Redistributions in binary form must reproduce the above | |
| 10 | * copyright notice, this list of conditions and the following | |
| 11 | * disclaimer in the documentation and/or other materials provided | |
| 12 | * with the distribution. 3) Neither the name of the jcabi.com nor | |
| 13 | * the names of its contributors may be used to endorse or promote | |
| 14 | * products derived from this software without specific prior written | |
| 15 | * permission. | |
| 16 | * | |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT | |
| 19 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | |
| 21 | * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
| 22 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
| 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
| 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
| 26 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
| 28 | * OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 | */ | |
| 30 | package com.jcabi.s3.cached; | |
| 31 | ||
| 32 | import com.amazonaws.services.s3.model.ObjectMetadata; | |
| 33 | import com.jcabi.aspects.Cacheable; | |
| 34 | import com.jcabi.aspects.Immutable; | |
| 35 | import com.jcabi.aspects.Loggable; | |
| 36 | import com.jcabi.s3.Bucket; | |
| 37 | import com.jcabi.s3.Ocket; | |
| 38 | import java.io.ByteArrayOutputStream; | |
| 39 | import java.io.IOException; | |
| 40 | import java.io.InputStream; | |
| 41 | import java.io.OutputStream; | |
| 42 | import lombok.EqualsAndHashCode; | |
| 43 | ||
| 44 | /** | |
| 45 | * Cached ocket. | |
| 46 | * | |
| 47 | * @author Yegor Bugayenko (yegor@tpc2.com) | |
| 48 | * @version $Id: 1fd00739747a295b7bb8af7d5941e2b706d16b74 $ | |
| 49 | * @since 0.8 | |
| 50 | */ | |
| 51 | 0 | @Immutable |
| 52 | 0 | @EqualsAndHashCode(of = "origin") |
| 53 | @Loggable(Loggable.DEBUG) | |
| 54 | public final class CdOcket implements Ocket { | |
| 55 | ||
| 56 | /** | |
| 57 | * Original ocket. | |
| 58 | */ | |
| 59 | private final transient Ocket origin; | |
| 60 | ||
| 61 | /** | |
| 62 | * Public ctor. | |
| 63 | * @param okt Ocket original | |
| 64 | */ | |
| 65 | 0 | public CdOcket(final Ocket okt) { |
| 66 | 0 | this.origin = okt; |
| 67 | 0 | } |
| 68 | ||
| 69 | @Override | |
| 70 | public Bucket bucket() { | |
| 71 | 0 | return new CdBucket(this.origin.bucket()); |
| 72 | } | |
| 73 | ||
| 74 | @Override | |
| 75 | public String key() { | |
| 76 | 0 | return this.origin.key(); |
| 77 | } | |
| 78 | ||
| 79 | @Override | |
| 80 | public ObjectMetadata meta() throws IOException { | |
| 81 | 0 | return this.origin.meta(); |
| 82 | } | |
| 83 | ||
| 84 | @Override | |
| 85 | @Cacheable | |
| 86 | public boolean exists() throws IOException { | |
| 87 | 0 | return this.origin.exists(); |
| 88 | } | |
| 89 | ||
| 90 | @Override | |
| 91 | public void read(final OutputStream output) throws IOException { | |
| 92 | 0 | output.write(this.read()); |
| 93 | 0 | } |
| 94 | ||
| 95 | @Override | |
| 96 | @Cacheable.FlushAfter | |
| 97 | public void write(final InputStream input, final ObjectMetadata meta) | |
| 98 | throws IOException { | |
| 99 | 0 | this.origin.write(input, meta); |
| 100 | 0 | } |
| 101 | ||
| 102 | @Override | |
| 103 | public int compareTo(final Ocket ocket) { | |
| 104 | 0 | return this.origin.compareTo(ocket); |
| 105 | } | |
| 106 | ||
| 107 | /** | |
| 108 | * Read byte array. | |
| 109 | * @return Bytes | |
| 110 | * @throws IOException If fails | |
| 111 | */ | |
| 112 | @Cacheable | |
| 113 | private byte[] read() throws IOException { | |
| 114 | 0 | final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 115 | 0 | this.origin.read(baos); |
| 116 | 0 | return baos.toByteArray(); |
| 117 | } | |
| 118 | ||
| 119 | } |