-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from wisdom-framework/encoding-implem
First steps to add encoding capability to outbound traffic
- Loading branch information
Showing
31 changed files
with
1,560 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,5 @@ key.array = a,b,c | |
|
||
other.conf = a_file.txt | ||
|
||
key.long = 9999999999999 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
content-manager/src/main/java/org/wisdom/content/codecs/AbstractDefInfCodec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package org.wisdom.content.codecs; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.zip.DeflaterOutputStream; | ||
import java.util.zip.GZIPInputStream; | ||
import java.util.zip.GZIPOutputStream; | ||
import java.util.zip.InflaterInputStream; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.wisdom.api.content.ContentCodec; | ||
|
||
/** | ||
* Abstract codec using an {@link DeflaterOutputStream} instance to encode and {@link InflaterInputStream} instance to decode. | ||
* Subclasses of this two classes can also be used, for instance ({@link GZIPOutputStream and {@link GZIPInputStream}} | ||
* <br/> | ||
* Subclasses should implements {@link #getEncoderClass} and {@link #getDecoderClass} to return the chosen encoder classes. | ||
* <br/> | ||
* @see ContentCodec | ||
*/ | ||
public abstract class AbstractDefInfCodec implements ContentCodec { | ||
|
||
@Override | ||
public InputStream encode(InputStream toEncode) throws IOException { | ||
ByteArrayOutputStream bout = new ByteArrayOutputStream(); | ||
|
||
OutputStream encoderout; | ||
try { | ||
encoderout = getEncoderClass().getConstructor(OutputStream.class).newInstance(bout); | ||
encoderout.write(IOUtils.toByteArray(toEncode)); | ||
encoderout.flush(); | ||
encoderout.close(); | ||
} | ||
catch (InstantiationException | IllegalAccessException | ||
| IllegalArgumentException | InvocationTargetException | ||
| NoSuchMethodException | SecurityException e) { | ||
e.printStackTrace(); | ||
//TODO notify encoding has not been done | ||
return toEncode; | ||
} | ||
|
||
toEncode.close(); | ||
|
||
bout.flush(); | ||
InputStream encoded = new ByteArrayInputStream(bout.toByteArray()); | ||
bout.close(); | ||
return encoded; | ||
} | ||
|
||
@Override | ||
public InputStream decode(InputStream toDecode) throws IOException { | ||
InputStream decoderin; | ||
try { | ||
decoderin = getDecoderClass().getConstructor(InputStream.class).newInstance(toDecode); | ||
} catch (InstantiationException | IllegalAccessException | ||
| IllegalArgumentException | InvocationTargetException | ||
| NoSuchMethodException | SecurityException e) { | ||
e.printStackTrace(); | ||
//TODO notify encoding has not been done | ||
return toDecode; | ||
} | ||
return decoderin; | ||
} | ||
|
||
@Override | ||
public abstract String getEncodingType(); | ||
|
||
@Override | ||
public abstract String getContentEncodingHeaderValue(); | ||
|
||
/** | ||
* @return Encoder class the codec use to encode data | ||
*/ | ||
public abstract Class<? extends DeflaterOutputStream> getEncoderClass(); | ||
|
||
/** | ||
* @return Decoder class the codec use to decode data | ||
*/ | ||
public abstract Class<? extends InflaterInputStream> getDecoderClass(); | ||
} |
Oops, something went wrong.