diff options
author | Eike Stepper | 2007-08-27 12:44:42 +0000 |
---|---|---|
committer | Eike Stepper | 2007-08-27 12:44:42 +0000 |
commit | c63b357a50bc6afcbd5bb6cdfff5a5aed4e1b577 (patch) | |
tree | 092069b8bb82a05d17d1b793398f4368b5c261d1 | |
parent | bd5f9cdc7fb5c41d2294cfc0ee7d2f02720eacb0 (diff) | |
download | cdo-c63b357a50bc6afcbd5bb6cdfff5a5aed4e1b577.tar.gz cdo-c63b357a50bc6afcbd5bb6cdfff5a5aed4e1b577.tar.xz cdo-c63b357a50bc6afcbd5bb6cdfff5a5aed4e1b577.zip |
*** empty log message ***
3 files changed, 169 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/XORInputStream.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/XORInputStream.java new file mode 100644 index 0000000000..b2033b30e5 --- /dev/null +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/XORInputStream.java @@ -0,0 +1,56 @@ +/*************************************************************************** + * Copyright (c) 2004 - 2007 Eike Stepper, Germany. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + **************************************************************************/ +package org.eclipse.net4j.util.io; + +import java.io.FilterInputStream; +import java.io.IOException; +import java.io.InputStream; + +/** + * @author Eike Stepper + */ +public class XORInputStream extends FilterInputStream +{ + private byte[] key; + + private int index; + + public XORInputStream(InputStream in, byte... key) + { + super(in); + this.key = key; + } + + public byte[] getKey() + { + return key; + } + + @Override + public int read() throws IOException + { + int b = super.read(); + if (b != -1) + { + if (key != null && key.length != 0) + { + if (index == key.length) + { + index = 0; + } + + b = b & 0x0f ^ key[index++]; + } + } + + return b; + } +} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/XOROutputStream.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/XOROutputStream.java new file mode 100644 index 0000000000..291ba708b7 --- /dev/null +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/XOROutputStream.java @@ -0,0 +1,52 @@ +/*************************************************************************** + * Copyright (c) 2004 - 2007 Eike Stepper, Germany. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + **************************************************************************/ +package org.eclipse.net4j.util.io; + +import java.io.FilterOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +/** + * @author Eike Stepper + */ +public class XOROutputStream extends FilterOutputStream +{ + private byte[] key; + + private int index; + + public XOROutputStream(OutputStream out, byte... key) + { + super(out); + this.key = key; + } + + public byte[] getKey() + { + return key; + } + + @Override + public void write(int b) throws IOException + { + if (key != null && key.length != 0) + { + if (index == key.length) + { + index = 0; + } + + b = b & 0x0f ^ key[index++]; + } + + super.write(b); + } +} diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/XORStreamWrapper.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/XORStreamWrapper.java new file mode 100644 index 0000000000..65853cb077 --- /dev/null +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/XORStreamWrapper.java @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (c) 2004 - 2007 Eike Stepper, Germany. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + **************************************************************************/ +package org.eclipse.net4j.util.io; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * @author Eike Stepper + */ +public class XORStreamWrapper implements IStreamWrapper<XORInputStream, XOROutputStream> +{ + private byte[] key; + + public XORStreamWrapper(byte[] key) + { + this.key = key; + } + + public byte[] getKey() + { + return key; + } + + public XORInputStream wrapInputStream(InputStream in) throws IOException + { + if (in instanceof XORInputStream) + { + return (XORInputStream)in; + } + + return new XORInputStream(in, key); + } + + public XOROutputStream wrapOutputStream(OutputStream out) throws IOException + { + if (out instanceof XOROutputStream) + { + return (XOROutputStream)out; + } + + return new XOROutputStream(out, key); + } + + public void finishInputStream(XORInputStream in) throws IOException + { + } + + public void finishOutputStream(XOROutputStream out) throws IOException + { + } +} |