001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.http.resource; 018 019import java.io.*; 020import java.util.function.*; 021 022import org.apache.juneau.http.entity.*; 023import org.apache.juneau.http.header.*; 024import org.apache.juneau.internal.*; 025 026/** 027 * A repeatable resource that obtains its content from a byte array. 028 * 029 * <h5 class='section'>See Also:</h5><ul> 030 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a> 031 * </ul> 032 */ 033public class ByteArrayResource extends BasicResource { 034 035 //----------------------------------------------------------------------------------------------------------------- 036 // Instance 037 //----------------------------------------------------------------------------------------------------------------- 038 039 /** 040 * Constructor. 041 */ 042 public ByteArrayResource() { 043 super(new ByteArrayEntity()); 044 } 045 046 /** 047 * Constructor. 048 * 049 * @param contentType The entity content type. 050 * @param contents The entity contents. 051 */ 052 public ByteArrayResource(ContentType contentType, byte[] contents) { 053 super(new ByteArrayEntity(contentType, contents)); 054 } 055 056 /** 057 * Copy constructor. 058 * 059 * @param copyFrom The bean being copied. 060 */ 061 protected ByteArrayResource(ByteArrayResource copyFrom) { 062 super(copyFrom); 063 } 064 065 @Override 066 public ByteArrayResource copy() { 067 return new ByteArrayResource(this); 068 } 069 @Override /* Overridden from BasicResource */ 070 public ByteArrayResource setCached() throws IOException{ 071 super.setCached(); 072 return this; 073 } 074 075 @Override /* Overridden from BasicResource */ 076 public ByteArrayResource setChunked() { 077 super.setChunked(); 078 return this; 079 } 080 081 @Override /* Overridden from BasicResource */ 082 public ByteArrayResource setChunked(boolean value) { 083 super.setChunked(value); 084 return this; 085 } 086 087 @Override /* Overridden from BasicResource */ 088 public ByteArrayResource setContent(Object value) { 089 super.setContent(value); 090 return this; 091 } 092 093 @Override /* Overridden from BasicResource */ 094 public ByteArrayResource setContent(Supplier<?> value) { 095 super.setContent(value); 096 return this; 097 } 098 099 @Override /* Overridden from BasicResource */ 100 public ByteArrayResource setContentEncoding(String value) { 101 super.setContentEncoding(value); 102 return this; 103 } 104 105 @Override /* Overridden from BasicResource */ 106 public ByteArrayResource setContentEncoding(ContentEncoding value) { 107 super.setContentEncoding(value); 108 return this; 109 } 110 111 @Override /* Overridden from BasicResource */ 112 public ByteArrayResource setContentLength(long value) { 113 super.setContentLength(value); 114 return this; 115 } 116 117 @Override /* Overridden from BasicResource */ 118 public ByteArrayResource setContentType(String value) { 119 super.setContentType(value); 120 return this; 121 } 122 123 @Override /* Overridden from BasicResource */ 124 public ByteArrayResource setContentType(ContentType value) { 125 super.setContentType(value); 126 return this; 127 } 128 129 @Override /* Overridden from BasicResource */ 130 public ByteArrayResource setHeaders(HeaderList value) { 131 super.setHeaders(value); 132 return this; 133 } 134 135 @Override /* Overridden from BasicResource */ 136 public ByteArrayResource setUnmodifiable() { 137 super.setUnmodifiable(); 138 return this; 139 } 140}