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.wicket.util.resource; 018 019import java.io.IOException; 020import java.io.InputStream; 021import java.time.Instant; 022import java.util.Locale; 023import org.apache.wicket.util.lang.Bytes; 024 025/** 026 * Base implementation of an IResourceStreamWriter so that you only have to override the 027 * {@link org.apache.wicket.util.resource.IResourceStreamWriter#write(java.io.OutputStream)}. Don't forget to overwrite the 028 * {@link org.apache.wicket.util.resource.IResourceStream#length()} method if you do know the total 029 * length that will be generated. 030 * 031 * @see org.apache.wicket.util.resource.IResourceStreamWriter 032 */ 033public abstract class AbstractResourceStreamWriter implements IResourceStreamWriter 034{ 035 private static final long serialVersionUID = 1L; 036 037 private Locale locale; 038 039 private String variation; 040 041 private String style; 042 043 /** 044 * Default implementation to returns {@code null}, i.e. chunked-encoding will be used. 045 * Do override this if you know the length up front. 046 */ 047 @Override 048 public Bytes length() 049 { 050 return null; 051 } 052 053 @Override 054 public Locale getLocale() 055 { 056 return locale; 057 } 058 059 @Override 060 public void setLocale(final Locale locale) 061 { 062 this.locale = locale; 063 } 064 065 /** 066 * Just returns now. 067 */ 068 @Override 069 public Instant lastModifiedTime() 070 { 071 return Instant.now(); 072 } 073 074 /** 075 * this method should not be used as it is not required for resource writers 076 */ 077 @Override 078 public final InputStream getInputStream() 079 { 080 throw new IllegalStateException("getInputStream() is not used with IResourceStreamWriter"); 081 } 082 083 /** 084 * {@inheritDoc} 085 * <p> 086 * This implementation does nothing. 087 * @throws IOException if an error occurred. 088 */ 089 @Override 090 public void close() throws IOException 091 { 092 } 093 094 @Override 095 public String getContentType() 096 { 097 return null; 098 } 099 100 @Override 101 public String getStyle() 102 { 103 return style; 104 } 105 106 @Override 107 public void setStyle(String style) 108 { 109 this.style = style; 110 } 111 112 @Override 113 public String getVariation() 114 { 115 return variation; 116 } 117 118 @Override 119 public void setVariation(String variation) 120 { 121 this.variation = variation; 122 } 123 124}