You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2012/06/18 11:37:16 UTC
[5/5] git commit: WICKET-4601 IResourceStreamWriter to take
OutputStream instead of Response
WICKET-4601 IResourceStreamWriter to take OutputStream instead of Response
IResourceStreamWriter#write() now accepts java.io.OutputStream (as in Wicket 1.4) instead of o.a.w.Response
Move IResourceStreamWriter and AbstractResourceStreamWriter to wicket-util since they don't have dependencies to classes in -core anymore. This way their package name is the same as in 1.5.x (before the OSGi-friendly change made in 6.x).
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/d2c87040
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/d2c87040
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/d2c87040
Branch: refs/heads/master
Commit: d2c870404709b994a2de9bc3e2e0fc1dc560b425
Parents: 1ab5628
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon Jun 18 11:55:15 2012 +0300
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon Jun 18 11:55:15 2012 +0300
----------------------------------------------------------------------
.../resource/AbstractResourceStreamWriter.java | 126 ---------------
.../core/util/resource/IResourceStreamWriter.java | 42 -----
.../wicket/request/resource/AbstractResource.java | 23 +---
.../request/resource/ResourceStreamResource.java | 4 +-
.../resource/AbstractResourceStreamWriter.java | 125 ++++++++++++++
.../util/resource/IResourceStreamWriter.java | 41 +++++
6 files changed, 169 insertions(+), 192 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/d2c87040/wicket-core/src/main/java/org/apache/wicket/core/util/resource/AbstractResourceStreamWriter.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/AbstractResourceStreamWriter.java b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/AbstractResourceStreamWriter.java
deleted file mode 100644
index efc7d3d..0000000
--- a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/AbstractResourceStreamWriter.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.core.util.resource;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Locale;
-
-import org.apache.wicket.util.lang.Bytes;
-import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
-import org.apache.wicket.util.time.Time;
-
-/**
- * Base implementation of an IResourceStreamWriter so that you only have to override the
- * {@link IResourceStreamWriter#write(org.apache.wicket.request.Response)}. Don't forget to overwrite the
- * {@link org.apache.wicket.util.resource.IResourceStream#length()} method if you do know the total
- * length that will be generated.
- *
- * @see IResourceStreamWriter
- */
-public abstract class AbstractResourceStreamWriter implements IResourceStreamWriter
-{
- private static final long serialVersionUID = 1L;
-
- private Locale locale;
-
- private String variation;
-
- private String style;
-
- /**
- * Default implementation to returns {@code null}, i.e. chunked-encoding will be used.
- * Do override this if you know the length up front.
- */
- @Override
- public Bytes length()
- {
- return null;
- }
-
- @Override
- public Locale getLocale()
- {
- return locale;
- }
-
- @Override
- public void setLocale(final Locale locale)
- {
- this.locale = locale;
- }
-
- /**
- * Just returns now.
- */
- @Override
- public Time lastModifiedTime()
- {
- return Time.now();
- }
-
- /**
- * this method should not be used as it is not required for resource writers
- */
- @Override
- public final InputStream getInputStream() throws ResourceStreamNotFoundException
- {
- throw new IllegalStateException("getInputStream is not used with IResourceStreamWriter");
- }
-
- /**
- * this method should not be used as it is not required for resource writers
- * <p>
- * resource write generate content directly, not using an input stream, so there's nothing to
- * close later.
- */
- @Override
- public final void close() throws IOException
- {
- }
-
- @Override
- public String getContentType()
- {
- return null;
- }
-
- @Override
- public String getStyle()
- {
- return style;
- }
-
- @Override
- public void setStyle(String style)
- {
- this.style = style;
- }
-
- @Override
- public String getVariation()
- {
- return variation;
- }
-
- @Override
- public void setVariation(String variation)
- {
- this.variation = variation;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/wicket/blob/d2c87040/wicket-core/src/main/java/org/apache/wicket/core/util/resource/IResourceStreamWriter.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/IResourceStreamWriter.java b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/IResourceStreamWriter.java
deleted file mode 100644
index 394f2a4..0000000
--- a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/IResourceStreamWriter.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.core.util.resource;
-
-import org.apache.wicket.request.Response;
-import org.apache.wicket.util.resource.IResourceStream;
-
-/**
- * Special IResourceStream implementation that a Resource can return when it directly wants to write
- * to an output stream instead of return the {@link IResourceStream#getInputStream()}. That one can
- * return null for a IResourceStreamWriter.
- *
- * This behavior comes in use when the resource is generated on the fly and should be streamed
- * directly to the client so that it won't be buffered completely if the generated resource is
- * really big.
- *
- * @author jcompagner
- */
-public interface IResourceStreamWriter extends IResourceStream
-{
- /**
- * Implement this method to write the resource data directly the the given OutputStream.
- *
- * @param output
- * The response where the resource can write its content into.
- */
- void write(Response output);
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/d2c87040/wicket-core/src/main/java/org/apache/wicket/request/resource/AbstractResource.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/request/resource/AbstractResource.java b/wicket-core/src/main/java/org/apache/wicket/request/resource/AbstractResource.java
index 7b2c623..8f79578 100644
--- a/wicket-core/src/main/java/org/apache/wicket/request/resource/AbstractResource.java
+++ b/wicket-core/src/main/java/org/apache/wicket/request/resource/AbstractResource.java
@@ -18,7 +18,6 @@ package org.apache.wicket.request.resource;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import java.util.HashSet;
import java.util.Set;
@@ -654,29 +653,9 @@ public abstract class AbstractResource implements IResource
protected final void writeStream(Attributes attributes, InputStream stream)
{
final Response response = attributes.getResponse();
- OutputStream s = new OutputStream()
- {
- @Override
- public void write(int b) throws IOException
- {
- response.write(new byte[] { (byte)b });
- }
-
- @Override
- public void write(byte[] b) throws IOException
- {
- response.write(b);
- }
-
- @Override
- public void write(byte[] b, int off, int len) throws IOException
- {
- response.write(b, off, len);
- }
- };
try
{
- Streams.copy(stream, s);
+ Streams.copy(stream, response.getOutputStream());
}
catch (IOException e)
{
http://git-wip-us.apache.org/repos/asf/wicket/blob/d2c87040/wicket-core/src/main/java/org/apache/wicket/request/resource/ResourceStreamResource.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/request/resource/ResourceStreamResource.java b/wicket-core/src/main/java/org/apache/wicket/request/resource/ResourceStreamResource.java
index 08b8a8e..2e0b49c 100644
--- a/wicket-core/src/main/java/org/apache/wicket/request/resource/ResourceStreamResource.java
+++ b/wicket-core/src/main/java/org/apache/wicket/request/resource/ResourceStreamResource.java
@@ -25,7 +25,7 @@ import org.apache.wicket.Application;
import org.apache.wicket.util.lang.Bytes;
import org.apache.wicket.util.lang.Checks;
import org.apache.wicket.util.resource.IResourceStream;
-import org.apache.wicket.core.util.resource.IResourceStreamWriter;
+import org.apache.wicket.util.resource.IResourceStreamWriter;
import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
import org.apache.wicket.util.time.Duration;
import org.apache.wicket.util.time.Time;
@@ -180,7 +180,7 @@ public class ResourceStreamResource extends AbstractResource
@Override
public void writeData(Attributes attributes)
{
- ((IResourceStreamWriter)resourceStream).write(attributes.getResponse());
+ ((IResourceStreamWriter)resourceStream).write(attributes.getResponse().getOutputStream());
close();
}
});
http://git-wip-us.apache.org/repos/asf/wicket/blob/d2c87040/wicket-util/src/main/java/org/apache/wicket/util/resource/AbstractResourceStreamWriter.java
----------------------------------------------------------------------
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/resource/AbstractResourceStreamWriter.java b/wicket-util/src/main/java/org/apache/wicket/util/resource/AbstractResourceStreamWriter.java
new file mode 100644
index 0000000..22f565b
--- /dev/null
+++ b/wicket-util/src/main/java/org/apache/wicket/util/resource/AbstractResourceStreamWriter.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.util.resource;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Locale;
+
+import org.apache.wicket.util.lang.Bytes;
+import org.apache.wicket.util.time.Time;
+
+/**
+ * Base implementation of an IResourceStreamWriter so that you only have to override the
+ * {@link org.apache.wicket.util.resource.IResourceStreamWriter#write(java.io.OutputStream)}. Don't forget to overwrite the
+ * {@link org.apache.wicket.util.resource.IResourceStream#length()} method if you do know the total
+ * length that will be generated.
+ *
+ * @see org.apache.wicket.util.resource.IResourceStreamWriter
+ */
+public abstract class AbstractResourceStreamWriter implements IResourceStreamWriter
+{
+ private static final long serialVersionUID = 1L;
+
+ private Locale locale;
+
+ private String variation;
+
+ private String style;
+
+ /**
+ * Default implementation to returns {@code null}, i.e. chunked-encoding will be used.
+ * Do override this if you know the length up front.
+ */
+ @Override
+ public Bytes length()
+ {
+ return null;
+ }
+
+ @Override
+ public Locale getLocale()
+ {
+ return locale;
+ }
+
+ @Override
+ public void setLocale(final Locale locale)
+ {
+ this.locale = locale;
+ }
+
+ /**
+ * Just returns now.
+ */
+ @Override
+ public Time lastModifiedTime()
+ {
+ return Time.now();
+ }
+
+ /**
+ * this method should not be used as it is not required for resource writers
+ */
+ @Override
+ public final InputStream getInputStream()
+ {
+ throw new IllegalStateException("getInputStream() is not used with IResourceStreamWriter");
+ }
+
+ /**
+ * this method should not be used as it is not required for resource writers
+ * <p>
+ * resource write generate content directly, not using an input stream, so there's nothing to
+ * close later.
+ */
+ @Override
+ public final void close() throws IOException
+ {
+ }
+
+ @Override
+ public String getContentType()
+ {
+ return null;
+ }
+
+ @Override
+ public String getStyle()
+ {
+ return style;
+ }
+
+ @Override
+ public void setStyle(String style)
+ {
+ this.style = style;
+ }
+
+ @Override
+ public String getVariation()
+ {
+ return variation;
+ }
+
+ @Override
+ public void setVariation(String variation)
+ {
+ this.variation = variation;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/wicket/blob/d2c87040/wicket-util/src/main/java/org/apache/wicket/util/resource/IResourceStreamWriter.java
----------------------------------------------------------------------
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/resource/IResourceStreamWriter.java b/wicket-util/src/main/java/org/apache/wicket/util/resource/IResourceStreamWriter.java
new file mode 100644
index 0000000..4a907f0
--- /dev/null
+++ b/wicket-util/src/main/java/org/apache/wicket/util/resource/IResourceStreamWriter.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.util.resource;
+
+import java.io.OutputStream;
+
+/**
+ * Special IResourceStream implementation that a Resource can return when it directly wants to write
+ * to an output stream instead of return the {@link IResourceStream#getInputStream()}. That one can
+ * return null for a IResourceStreamWriter.
+ *
+ * This behavior comes in use when the resource is generated on the fly and should be streamed
+ * directly to the client so that it won't be buffered completely if the generated resource is
+ * really big.
+ *
+ * @author jcompagner
+ */
+public interface IResourceStreamWriter extends IResourceStream
+{
+ /**
+ * Implement this method to write the resource data directly the the given {@link OutputStream}.
+ *
+ * @param output
+ * The response where the resource can write its content into.
+ */
+ void write(OutputStream output);
+}