Coverage Report - com.jcabi.github.Content
 
Classes in this File Line Coverage Branch Coverage Complexity
Content
N/A
N/A
1
Content$Smart
66%
16/24
0%
0/16
1
Content$Smart$AjcClosure1
100%
1/1
N/A
1
Content$Smart$AjcClosure11
100%
1/1
N/A
1
Content$Smart$AjcClosure13
100%
1/1
N/A
1
Content$Smart$AjcClosure15
100%
1/1
N/A
1
Content$Smart$AjcClosure17
100%
1/1
N/A
1
Content$Smart$AjcClosure19
0%
0/1
N/A
1
Content$Smart$AjcClosure21
0%
0/1
N/A
1
Content$Smart$AjcClosure23
0%
0/1
N/A
1
Content$Smart$AjcClosure25
100%
1/1
N/A
1
Content$Smart$AjcClosure27
100%
1/1
N/A
1
Content$Smart$AjcClosure29
0%
0/1
N/A
1
Content$Smart$AjcClosure3
100%
1/1
N/A
1
Content$Smart$AjcClosure5
100%
1/1
N/A
1
Content$Smart$AjcClosure7
100%
1/1
N/A
1
Content$Smart$AjcClosure9
100%
1/1
N/A
1
 
 1  2
 /**
 2  
  * Copyright (c) 2013-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.github;
 31  
 
 32  
 import com.jcabi.aspects.Immutable;
 33  
 import com.jcabi.aspects.Loggable;
 34  
 import java.io.IOException;
 35  
 import java.io.InputStream;
 36  
 import java.net.URL;
 37  
 import javax.json.JsonObject;
 38  
 import javax.validation.constraints.NotNull;
 39  
 import javax.xml.bind.DatatypeConverter;
 40  
 import lombok.EqualsAndHashCode;
 41  
 import lombok.ToString;
 42  
 
 43  
 /**
 44  
  * Github content.
 45  
  *
 46  
  * @author Andres Candal (andres.candal@rollasolution.com)
 47  
  * @version $Id$
 48  
  * @since 0.8
 49  
  * @see <a href="http://developer.github.com/v3/repos/contents/">Contents API</a>
 50  
  */
 51  
 @Immutable
 52  
 @SuppressWarnings("PMD.TooManyMethods")
 53  
 public interface Content extends Comparable<Content>,
 54  
     JsonReadable, JsonPatchable {
 55  
 
 56  
     /**
 57  
      * Repository we're in.
 58  
      * @return Repo
 59  
      */
 60  
     @NotNull(message = "repository is never NULL")
 61  
     Repo repo();
 62  
 
 63  
     /**
 64  
      * Get its path name.
 65  
      * @return The path name
 66  
      */
 67  
     @NotNull(message = "path is never NULL")
 68  
     String path();
 69  
 
 70  
     /**
 71  
      * Get the raw contents.
 72  
      * @throws IOException If an IO error occurs
 73  
      * @return Input stream of the raw content
 74  
      */
 75  
     @NotNull(message = "raw is never NULL")
 76  
     InputStream raw() throws IOException;
 77  
 
 78  
     /**
 79  
      * Smart Content with extra features.
 80  
      */
 81  0
     @Immutable
 82  0
     @ToString
 83  
     @Loggable(Loggable.DEBUG)
 84  0
     @EqualsAndHashCode(of = { "content", "jsn" })
 85  
     final class Smart implements Content {
 86  
         /**
 87  
          * Encapsulated content.
 88  
          */
 89  
         private final transient Content content;
 90  
         /**
 91  
          * SmartJson object for convenient JSON parsing.
 92  
          */
 93  
         private final transient SmartJson jsn;
 94  
         /**
 95  
          * Public ctor.
 96  
          * @param cont Content
 97  
          */
 98  
         public Smart(
 99  
             @NotNull(message = "content is never NULL")
 100  20
             final Content cont) {
 101  20
             this.content = cont;
 102  20
             this.jsn = new SmartJson(cont);
 103  20
         }
 104  
         /**
 105  
          * Get its name.
 106  
          * @return Name of content
 107  
          * @throws IOException If there is any I/O problem
 108  
          */
 109  
         @NotNull(message = "name is never NULL")
 110  
         public String name() throws IOException {
 111  10
             return this.jsn.text("name");
 112  
         }
 113  
         /**
 114  
          * Get its type.
 115  
          * @return Type of content
 116  
          * @throws IOException If there is any I/O problem
 117  
          */
 118  
         @NotNull(message = "type is never NULL")
 119  
         public String type() throws IOException {
 120  2
             return this.jsn.text("type");
 121  
         }
 122  
         /**
 123  
          * Get its size.
 124  
          * @return Size content
 125  
          * @throws IOException If it fails
 126  
          */
 127  
         public int size() throws IOException {
 128  2
             return this.jsn.number("size");
 129  
         }
 130  
         /**
 131  
          * Get its sha hash.
 132  
          * @return Sha hash of content
 133  
          * @throws IOException If there is any I/O problem
 134  
          */
 135  
         @NotNull(message = "sha is never NULL")
 136  
         public String sha() throws IOException {
 137  6
             return this.jsn.text("sha");
 138  
         }
 139  
         /**
 140  
          * Get its URL.
 141  
          * @return URL of content
 142  
          * @throws IOException If there is any I/O problem
 143  
          */
 144  
         @NotNull(message = "url is never NULL")
 145  
         public URL url() throws IOException {
 146  2
             return new URL(this.jsn.text("url"));
 147  
         }
 148  
         /**
 149  
          * Get its HTML URL.
 150  
          * @return URL of content
 151  
          * @throws IOException If there is any I/O problem
 152  
          */
 153  
         @NotNull(message = "html url is never NULL")
 154  
         public URL htmlUrl() throws IOException {
 155  2
             return new URL(this.jsn.text("html_url"));
 156  
         }
 157  
         /**
 158  
          * Get its GIT URL.
 159  
          * @return URL of content
 160  
          * @throws IOException If there is any I/O problem
 161  
          */
 162  
         @NotNull(message = "git url is never NULL")
 163  
         public URL gitUrl() throws IOException {
 164  2
             return new URL(this.jsn.text("git_url"));
 165  
         }
 166  
         /**
 167  
          * Get its encoded content.
 168  
          * @return Base64 encoded content
 169  
          * @throws IOException If there is any I/O problem
 170  
          */
 171  
         @NotNull(message = "content is never NULL")
 172  
         public String content() throws IOException {
 173  14
             return this.jsn.text("content");
 174  
         }
 175  
         /**
 176  
          * Get its decoded content.
 177  
          * @return Decoded content
 178  
          * @throws IOException If there is any I/O problem
 179  
          */
 180  
         @NotNull(message = "decoded is never NULL")
 181  
         public byte[] decoded() throws IOException {
 182  2
             return DatatypeConverter.parseBase64Binary(this.content());
 183  
         }
 184  
         @Override
 185  
         public int compareTo(
 186  
             @NotNull(message = "cont can't be NULL") final Content cont
 187  
         ) {
 188  0
             return this.content.compareTo(cont);
 189  
         }
 190  
         @Override
 191  
         public void patch(
 192  
             @NotNull(message = "JSON is never NULL")final JsonObject json)
 193  
             throws IOException {
 194  0
             this.content.patch(json);
 195  0
         }
 196  
         @Override
 197  
         @NotNull(message = "JSON is never NULL")
 198  
         public JsonObject json() throws IOException {
 199  0
             return this.content.json();
 200  
         }
 201  
         @Override
 202  
         @NotNull(message = "Repository is never NULL")
 203  
         public Repo repo() {
 204  2
             return this.content.repo();
 205  
         }
 206  
         @Override
 207  
         @NotNull(message = "path is never NULL")
 208  
         public String path() {
 209  12
             return this.content.path();
 210  
         }
 211  
         @Override
 212  
         @NotNull(message = "input stream is never NULL")
 213  
         public InputStream raw() throws IOException {
 214  0
             return this.content.raw();
 215  
         }
 216  
     }
 217  
 }