summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/thrift
diff options
context:
space:
mode:
authorSimon Rettberg2015-09-07 18:20:58 +0200
committerSimon Rettberg2015-09-07 18:20:58 +0200
commit2f140304dd193763b2aa9d509f972c6f23202e93 (patch)
tree8639a625543d78b35caccfe3dcdfa4740ba6d917 /src/main/java/org/openslx/imagemaster/thrift
parentStuff (diff)
downloadmasterserver-2f140304dd193763b2aa9d509f972c6f23202e93.tar.gz
masterserver-2f140304dd193763b2aa9d509f972c6f23202e93.tar.xz
masterserver-2f140304dd193763b2aa9d509f972c6f23202e93.zip
Start adapting to new DB/Thrift model
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/thrift')
-rw-r--r--src/main/java/org/openslx/imagemaster/thrift/server/TBinaryProtocolSafe.java122
1 files changed, 0 insertions, 122 deletions
diff --git a/src/main/java/org/openslx/imagemaster/thrift/server/TBinaryProtocolSafe.java b/src/main/java/org/openslx/imagemaster/thrift/server/TBinaryProtocolSafe.java
deleted file mode 100644
index 08654d6..0000000
--- a/src/main/java/org/openslx/imagemaster/thrift/server/TBinaryProtocolSafe.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package org.openslx.imagemaster.thrift.server;
-
-import java.io.UnsupportedEncodingException;
-import java.nio.ByteBuffer;
-
-import org.apache.thrift.TException;
-import org.apache.thrift.protocol.TBinaryProtocol;
-import org.apache.thrift.protocol.TMessage;
-import org.apache.thrift.protocol.TProtocol;
-import org.apache.thrift.protocol.TProtocolException;
-import org.apache.thrift.protocol.TProtocolFactory;
-import org.apache.thrift.transport.TTransport;
-
-/**
- * Binary protocol implementation for thrift.
- * Will not read messages bigger than 12MiB.
- *
- */
-public class TBinaryProtocolSafe extends TBinaryProtocol
-{
- /**
- * Factory
- */
- @SuppressWarnings( "serial" )
- public static class Factory implements TProtocolFactory
- {
-
- protected boolean strictRead_ = false;
- protected boolean strictWrite_ = true;
-
- public Factory()
- {
- this( false, true );
- }
-
- public Factory(boolean strictRead, boolean strictWrite)
- {
- strictRead_ = strictRead;
- strictWrite_ = strictWrite;
- }
-
- public TProtocol getProtocol( TTransport trans )
- {
- return new TBinaryProtocolSafe( trans, strictRead_, strictWrite_ );
- }
- }
-
- private static final int maxLen = 12 * 1024 * 1024; // 12 MiB
-
- /**
- * Constructor
- */
- public TBinaryProtocolSafe(TTransport trans)
- {
- this( trans, false, true );
- }
-
- public TBinaryProtocolSafe(TTransport trans, boolean strictRead, boolean strictWrite)
- {
- super( trans );
- strictRead_ = strictRead;
- strictWrite_ = strictWrite;
- }
-
- /**
- * Reading methods.
- */
-
- public TMessage readMessageBegin() throws TException
- {
- int size = readI32();
- if ( size > maxLen )
- throw new TProtocolException( TProtocolException.SIZE_LIMIT, "Payload too big." );
- if ( size < 0 ) {
- int version = size & VERSION_MASK;
- if ( version != VERSION_1 ) {
- throw new TProtocolException( TProtocolException.BAD_VERSION, "Bad version in readMessageBegin" );
- }
- return new TMessage( readString(), (byte) ( size & 0x000000ff ), readI32() );
- } else {
- if ( strictRead_ ) {
- throw new TProtocolException( TProtocolException.BAD_VERSION, "Missing version in readMessageBegin, old client?" );
- }
- return new TMessage( readStringBody( size ), readByte(), readI32() );
- }
- }
-
- public String readString() throws TException
- {
- int size = readI32();
- if ( size > maxLen )
- throw new TProtocolException( TProtocolException.SIZE_LIMIT, "Payload too big." );
- if ( trans_.getBytesRemainingInBuffer() >= size ) {
- try {
- String s = new String( trans_.getBuffer(), trans_.getBufferPosition(), size, "UTF-8" );
- trans_.consumeBuffer( size );
- return s;
- } catch ( UnsupportedEncodingException e ) {
- throw new TException( "JVM DOES NOT SUPPORT UTF-8" );
- }
- }
-
- return readStringBody( size );
- }
-
- public ByteBuffer readBinary() throws TException
- {
- int size = readI32();
- if ( size > maxLen )
- throw new TProtocolException( TProtocolException.SIZE_LIMIT, "Payload too big." );
- if ( trans_.getBytesRemainingInBuffer() >= size ) {
- ByteBuffer bb = ByteBuffer.wrap( trans_.getBuffer(), trans_.getBufferPosition(), size );
- trans_.consumeBuffer( size );
- return bb;
- }
-
- byte[] buf = new byte[ size ];
- trans_.readAll( buf, 0, size );
- return ByteBuffer.wrap( buf );
- }
-
-}