Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEsteban Dugueperoux2016-02-05 12:18:49 +0000
committerEike Stepper2016-02-05 12:49:26 +0000
commit3161838c989d7ebfc009eded4ac95698bb2a70a4 (patch)
treef5a8b11dcac8216a7f1e4f8a60f17cded0f5ab39 /plugins/org.eclipse.net4j.util/src/org
parentf11f14a3b2711978ad96d835dd69b2384721bb37 (diff)
downloadcdo-3161838c989d7ebfc009eded4ac95698bb2a70a4.tar.gz
cdo-3161838c989d7ebfc009eded4ac95698bb2a70a4.tar.xz
cdo-3161838c989d7ebfc009eded4ac95698bb2a70a4.zip
[482686] Have IStreamWrapper configurable through cdo-server.xml
For example: <acceptor type="tcp" listenAddr="0.0.0.0" port="2036"> <streamWrapper type="gzip" protocol="cdo" description="bufferSize=256,compressionLevel=3"/> </acceptor> <streamWrapper type="gzip"/> Change-Id: I7e04ad92b081a454ab90b4ace5dc328f3fd12bfe Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=482686 Signed-off-by: Esteban Dugueperoux <esteban.dugueperoux@obeo.fr> Signed-off-by: Eike Stepper <stepper@esc-net.de>
Diffstat (limited to 'plugins/org.eclipse.net4j.util/src/org')
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/GZIPStreamWrapper.java111
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IStreamWrapper.java18
2 files changed, 96 insertions, 33 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/GZIPStreamWrapper.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/GZIPStreamWrapper.java
index 65cc8b40c5..282a01573d 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/GZIPStreamWrapper.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/GZIPStreamWrapper.java
@@ -10,23 +10,47 @@
*/
package org.eclipse.net4j.util.io;
-import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
+import org.eclipse.net4j.util.factory.ProductCreationException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
+import java.util.zip.Deflater;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
/**
* @author Eike Stepper
+ * @since 3.6
*/
public class GZIPStreamWrapper implements IStreamWrapper
{
+ /**
+ * @since 3.6
+ */
+ public static final int DEFAULT_BUFFER_SIZE = 512;
+
+ /**
+ * @since 3.6
+ */
+ public static final int DEFAULT_COMPRESSION_LEVEL = Deflater.BEST_SPEED;
+
+ private final int bufferSize;
+
+ private final int compressionLevel;
+
public GZIPStreamWrapper()
{
+ this(DEFAULT_BUFFER_SIZE, DEFAULT_COMPRESSION_LEVEL);
+ }
+
+ /**
+ * @since 3.6
+ */
+ public GZIPStreamWrapper(int bufferSize, int compressionLevel)
+ {
+ this.bufferSize = bufferSize;
+ this.compressionLevel = compressionLevel;
}
public GZIPInputStream wrapInputStream(InputStream in) throws IOException
@@ -36,7 +60,7 @@ public class GZIPStreamWrapper implements IStreamWrapper
return (GZIPInputStream)in;
}
- return new GZIPInputStream(in);
+ return new GZIPInputStream(in, bufferSize);
}
public GZIPOutputStream wrapOutputStream(OutputStream out) throws IOException
@@ -46,7 +70,12 @@ public class GZIPStreamWrapper implements IStreamWrapper
return (GZIPOutputStream)out;
}
- return new GZIPOutputStream(out);
+ return new GZIPOutputStream(out, bufferSize)
+ {
+ {
+ def.setLevel(compressionLevel);
+ }
+ };
}
public void finishInputStream(InputStream in) throws IOException
@@ -59,43 +88,59 @@ public class GZIPStreamWrapper implements IStreamWrapper
}
/**
- * TODO Move or remove me
+ * @author Esteban Dugueperoux
+ * @since 3.6
*/
- public static void main(String[] args) throws Exception
+ public static class Factory extends IStreamWrapper.Factory
{
- final PipedOutputStream pos = new PipedOutputStream();
- @SuppressWarnings("resource")
- final PipedInputStream pis = new PipedInputStream(pos);
+ public static final String TYPE = "gzip"; //$NON-NLS-1$
- final GZIPOutputStream gos = new GZIPOutputStream(pos);
- final byte[] out = "eike".getBytes(); //$NON-NLS-1$
+ public Factory()
+ {
+ super(TYPE);
+ }
- Thread thread = new Thread()
+ @Override
+ public IStreamWrapper create(String description) throws ProductCreationException
{
- @Override
- public void run()
- {
- try
- {
- GZIPInputStream gis = new GZIPInputStream(pis);
+ int bufferSize = GZIPStreamWrapper.DEFAULT_BUFFER_SIZE;
+ int compressionLevel = GZIPStreamWrapper.DEFAULT_COMPRESSION_LEVEL;
- byte[] in = new byte[out.length];
- gis.read(in);
- gis.close();
- }
- catch (IOException ex)
+ String[] properties = description.split(",");
+ for (String property : properties)
+ {
+ String[] tokens = property.split("=");
+ if (tokens.length == 2)
{
- throw new IORuntimeException(ex);
+ String propertyName = tokens[0];
+ String propertyValue = tokens[1];
+
+ if ("bufferSize".equals(propertyName))
+ {
+ try
+ {
+ bufferSize = Integer.valueOf(propertyValue);
+ }
+ catch (NumberFormatException ex)
+ {
+ throw new ProductCreationException(ex);
+ }
+ }
+ else if ("compressionLevel".equals(propertyName))
+ {
+ try
+ {
+ compressionLevel = Integer.valueOf(propertyValue);
+ }
+ catch (NumberFormatException ex)
+ {
+ throw new ProductCreationException(ex);
+ }
+ }
}
}
- };
- thread.start();
- ConcurrencyUtil.sleep(1000);
-
- gos.write(out);
- gos.close();
-
- ConcurrencyUtil.sleep(2000);
+ return new GZIPStreamWrapper(bufferSize, compressionLevel);
+ }
}
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IStreamWrapper.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IStreamWrapper.java
index a43985fc47..d92b4eca9d 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IStreamWrapper.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IStreamWrapper.java
@@ -10,6 +10,8 @@
*/
package org.eclipse.net4j.util.io;
+import org.eclipse.net4j.util.factory.ProductCreationException;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -26,4 +28,20 @@ public interface IStreamWrapper
public void finishInputStream(InputStream in) throws IOException;
public void finishOutputStream(OutputStream out) throws IOException;
+
+ /**
+ * @author Esteban Dugueperoux
+ * @since 3.6
+ */
+ public static abstract class Factory extends org.eclipse.net4j.util.factory.Factory
+ {
+ public static final String PRODUCT_GROUP = "org.eclipse.net4j.streamWrappers"; //$NON-NLS-1$
+
+ public Factory(String type)
+ {
+ super(PRODUCT_GROUP, type);
+ }
+
+ public abstract IStreamWrapper create(String description) throws ProductCreationException;
+ }
}

Back to the top