当前位置: 首页>>代码示例>>Java>>正文


Java Buffer类代码示例

本文整理汇总了Java中org.fusesource.hawtbuf.Buffer的典型用法代码示例。如果您正苦于以下问题:Java Buffer类的具体用法?Java Buffer怎么用?Java Buffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Buffer类属于org.fusesource.hawtbuf包,在下文中一共展示了Buffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: unmarshal

import org.fusesource.hawtbuf.Buffer; //导入依赖的package包/类
public synchronized Object unmarshal(Buffer sequence) throws IOException {
    bytesIn.restart(sequence);
    // DataByteArrayInputStreamStream dis = new DataByteArrayInputStreamStream(new
    // ByteArrayInputStream(sequence));

    if (!sizePrefixDisabled) {
        int size = bytesIn.readInt();
        if (sequence.getLength() - 4 != size) {
            // throw new IOException("Packet size does not match marshaled
            // size");
        }

        if (size > maxFrameSize) {
            throw new IOException(
                    "Frame size of " + (size / (1024 * 1024)) +
                    " MB larger than max allowed " +
                            (maxFrameSize / (1024 * 1024)) + " MB");
        }
    }

    Object command = doUnmarshal(bytesIn);
    // if( !cacheEnabled && ((DataStructure)command).isMarshallAware() ) {
    // ((MarshallAware) command).setCachedMarshalledForm(this, sequence);
    // }
    return command;
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:27,代码来源:OpenWireFormat.java

示例2: tightMarshalNestedObject1

import org.fusesource.hawtbuf.Buffer; //导入依赖的package包/类
public int tightMarshalNestedObject1(DataStructure o, BooleanStream bs) throws IOException {
    bs.writeBoolean(o != null);
    if (o == null) {
        return 0;
    }

    if (o.isMarshallAware()) {
        // MarshallAware ma = (MarshallAware)o;
        Buffer sequence = null;
        // sequence=ma.getCachedMarshalledForm(this);
        bs.writeBoolean(sequence != null);
        if (sequence != null) {
            return 1 + sequence.getLength();
        }
    }

    byte type = o.getDataStructureType();
    DataStreamMarshaller dsm = (DataStreamMarshaller) dataMarshallers[type & 0xFF];
    if (dsm == null) {
        throw new IOException("Unknown data type: " + type);
    }
    return 1 + dsm.tightMarshal1(this, o, bs);
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:24,代码来源:OpenWireFormat.java

示例3: looseMarshalNestedObject

import org.fusesource.hawtbuf.Buffer; //导入依赖的package包/类
public void looseMarshalNestedObject(DataStructure o, DataByteArrayOutputStream dataOut) throws IOException {
    dataOut.writeBoolean(o != null);
    if (o != null) {
        if( o instanceof Message) {
            if( !isTightEncodingEnabled() && !isCacheEnabled() ) {
                CachedEncodingTrait encoding = ((Message) o).getCachedEncoding();
                if( encoding !=null && !encoding.tight() && encoding.version()==getVersion()) {
                    Buffer buffer = encoding.buffer();
                    dataOut.write(buffer.data, buffer.offset + 4, buffer.length() - 4);
                    return;
                }
            }
        }
        byte type = o.getDataStructureType();
        dataOut.writeByte(type);
        DataStreamMarshaller dsm = (DataStreamMarshaller) dataMarshallers[type & 0xFF];
        if (dsm == null) {
            throw new IOException("Unknown data type: " + type);
        }
        dsm.looseMarshal(this, o, dataOut);
    }
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:23,代码来源:OpenWireFormat.java

示例4: storeContent

import org.fusesource.hawtbuf.Buffer; //导入依赖的package包/类
private void storeContent() {
    try {
        if (dataOut != null) {
            dataOut.close();
            Buffer bs = bytesOut.toBuffer();
            if (compressed) {
                int pos = bs.offset;
                bs.offset = 0;
                BufferEditor e = BufferEditor.big(bs);
                e.writeInt(length);
                bs.offset = pos;
            }
            setContent(bs);
            bytesOut = null;
            dataOut = null;
        }
    } catch (IOException ioe) {
        throw new RuntimeException(ioe.getMessage(), ioe); // TODO verify
                                                            // RuntimeException
    }
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:22,代码来源:ActiveMQBytesMessage.java

示例5: connectionListener

import org.fusesource.hawtbuf.Buffer; //导入依赖的package包/类
private Listener connectionListener() {
	return new Listener() {

		@Override
		public void onPublish(UTF8Buffer topic, Buffer body, Runnable ack) {
			// nothing to do
		}

		@Override
		public void onFailure(Throwable value) {
			// nothing to do
		}

		@Override
		public void onDisconnected() {
			fireConnectionLost();
		}

		@Override
		public void onConnected() {
			fireReconnected();
		}
	};
}
 
开发者ID:Ardulink,项目名称:Ardulink-2,代码行数:25,代码来源:MqttLink.java

示例6: testFlush

import org.fusesource.hawtbuf.Buffer; //导入依赖的package包/类
@Test
public void testFlush() throws Exception {
	final Buffer value = Buffer.ascii("TESTDATA");
	codec.write(value);
	final int bytesThatWillBeWritten = value.length();
	expect(writableByteChannel.write((ByteBuffer) anyObject())).andAnswer(createWriteAnswer(bytesThatWillBeWritten));
	replay(writableByteChannel);

	final BufferState state = codec.flush();

	assertEquals(BufferState.EMPTY, state);
	assertEquals(false, codec.full());
	assertEquals(true, codec.empty());
	assertEquals(bytesThatWillBeWritten, codec.getWriteCounter());

	assertEquals(BufferState.WAS_EMPTY, codec.flush());
}
 
开发者ID:apache,项目名称:aries-rsa,代码行数:18,代码来源:LengthPrefixedCodecTest.java

示例7: get

import org.fusesource.hawtbuf.Buffer; //导入依赖的package包/类
public Exchange get(final CamelContext camelContext, final String key) {
    Exchange answer = null;

    try {
        byte[] lDbKey = keyBuilder(repositoryName, key);
        LOG.trace("Getting key index {}", key);
        byte[] rc = levelDBFile.getDb().get(lDbKey);

        if (rc != null) {
            answer = codec.unmarshallExchange(camelContext, new Buffer(rc));
        }
    } catch (IOException e) {
        throw new RuntimeException("Error getting key " + key + " from repository " + repositoryName, e);
    }

    LOG.debug("Getting key  [{}] -> {}", key, answer);
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:LevelDBAggregationRepository.java

示例8: recover

import org.fusesource.hawtbuf.Buffer; //导入依赖的package包/类
public Exchange recover(CamelContext camelContext, final String exchangeId) {
    Exchange answer = null;

    try {
        byte[] completedLDBKey = keyBuilder(getRepositoryNameCompleted(), exchangeId);

        byte[] rc = levelDBFile.getDb().get(completedLDBKey);

        if (rc != null) {
            answer = codec.unmarshallExchange(camelContext, new Buffer(rc));
        }
    } catch (IOException e) {
        throw new RuntimeException("Error recovering exchangeId " + exchangeId + " from repository " + repositoryName, e);
    }

    LOG.debug("Recovering exchangeId [{}] -> {}", exchangeId, answer);
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:LevelDBAggregationRepository.java

示例9: marshallExchange

import org.fusesource.hawtbuf.Buffer; //导入依赖的package包/类
public Buffer marshallExchange(CamelContext camelContext, Exchange exchange, boolean allowSerializedHeaders) throws IOException {
    DataByteArrayOutputStream baos = new DataByteArrayOutputStream();
    // use DefaultExchangeHolder to marshal to a serialized object
    DefaultExchangeHolder pe = DefaultExchangeHolder.marshal(exchange, false, allowSerializedHeaders);
    // add the aggregated size and timeout property as the only properties we want to retain
    DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_SIZE, exchange.getProperty(Exchange.AGGREGATED_SIZE, Integer.class));
    DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_TIMEOUT, exchange.getProperty(Exchange.AGGREGATED_TIMEOUT, Long.class));
    // add the aggregated completed by property to retain
    DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_COMPLETED_BY, exchange.getProperty(Exchange.AGGREGATED_COMPLETED_BY, String.class));
    // add the aggregated correlation key property to retain
    DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_CORRELATION_KEY, exchange.getProperty(Exchange.AGGREGATED_CORRELATION_KEY, String.class));
    // and a guard property if using the flexible toolbox aggregator
    DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_COLLECTION_GUARD, exchange.getProperty(Exchange.AGGREGATED_COLLECTION_GUARD, String.class));
    // persist the from endpoint as well
    if (exchange.getFromEndpoint() != null) {
        DefaultExchangeHolder.addProperty(pe, "CamelAggregatedFromEndpoint", exchange.getFromEndpoint().getEndpointUri());
    }
    exchangeCodec.encode(pe, baos);
    return baos.toBuffer();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:LevelDBCamelCodec.java

示例10: getRepositoryIndex

import org.fusesource.hawtbuf.Buffer; //导入依赖的package包/类
public SortedIndex<Buffer, Buffer> getRepositoryIndex(Transaction tx, String name, boolean create) {
    SortedIndex<Buffer, Buffer> answer = null;

    SortedIndex<String, Integer> indexes = ROOT_INDEXES_FACTORY.open(tx);
    Integer location = indexes.get(name);

    if (create && location == null) {
        // create it..
        SortedIndex<Buffer, Buffer> created = INDEX_FACTORY.create(tx);
        int page = created.getIndexLocation();

        // add it to indexes so we can find it the next time
        indexes.put(name, page);

        LOG.debug("Created new repository index with name {} at location {}", name, page);

        answer = created;
    } else if (location != null) {
        LOG.trace("Repository index with name {} at location {}", name, location);
        answer = INDEX_FACTORY.open(tx, location);
    }

    LOG.trace("Repository index with name {} -> {}", name, answer);
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:HawtDBFile.java

示例11: confirm

import org.fusesource.hawtbuf.Buffer; //导入依赖的package包/类
public void confirm(final CamelContext camelContext, final String exchangeId) {
    LOG.debug("Confirming exchangeId [{}]", exchangeId);
    try {
        final Buffer confirmKeyBuffer = codec.marshallKey(exchangeId);
        hawtDBFile.execute(new Work<Buffer>() {
            public Buffer execute(Transaction tx) {
                SortedIndex<Buffer, Buffer> indexCompleted = hawtDBFile.getRepositoryIndex(tx, getRepositoryNameCompleted(), true);
                Buffer buffer = indexCompleted.remove(confirmKeyBuffer);
                LOG.trace("Removed confirm index {} -> {}", confirmKeyBuffer, buffer);
                return buffer;
            }

            @Override
            public String toString() {
                return "Confirming exchangeId [" + exchangeId + "]";
            }
        });

    } catch (IOException e) {
        throw new RuntimeException("Error confirming exchangeId " + exchangeId + " from repository " + repositoryName, e);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:HawtDBAggregationRepository.java

示例12: size

import org.fusesource.hawtbuf.Buffer; //导入依赖的package包/类
private int size(final String repositoryName) {
    int answer = hawtDBFile.execute(new Work<Integer>() {
        public Integer execute(Transaction tx) {
            SortedIndex<Buffer, Buffer> index = hawtDBFile.getRepositoryIndex(tx, repositoryName, false);
            return index != null ? index.size() : 0;
        }

        @Override
        public String toString() {
            return "Size[" + repositoryName + "]";
        }
    });

    LOG.debug("Size of repository [{}] -> {}", repositoryName, answer);
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:HawtDBAggregationRepository.java

示例13: processCommand

import org.fusesource.hawtbuf.Buffer; //导入依赖的package包/类
@Override
protected void processCommand(ByteBuffer plain) throws Exception {

    byte[] fill = new byte[plain.remaining()];
    plain.get(fill);

    ByteBuffer payload = ByteBuffer.wrap(fill);

    if (magic.position() != 8) {

        while (payload.hasRemaining() && magic.position() < 8) {
            magic.put(payload.get());
        }

        if (!magic.hasRemaining()) {
            magic.flip();
            doConsume(new AmqpHeader(new Buffer(magic)));
            magic.position(8);
        }
    }

    if (payload.hasRemaining()) {
        doConsume(AmqpSupport.toBuffer(payload));
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:26,代码来源:AmqpNioSslTransport.java

示例14: unmarshal

import org.fusesource.hawtbuf.Buffer; //导入依赖的package包/类
public Object unmarshal(DataInput dataIn) throws IOException {
    if( !magicRead ) {
        Buffer magic = new Buffer(8);
        magic.readFrom(dataIn);
        magicRead = true;
        return new AmqpHeader(magic);
    } else {
        int size = dataIn.readInt();
        if( size > maxFrameSize) {
            throw new AmqpProtocolException("Frame size exceeded max frame length.");
        }
        Buffer frame = new Buffer(size);
        frame.bigEndianEditor().writeInt(size);
        frame.readFrom(dataIn);
        frame.clear();
        return frame;
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:19,代码来源:AmqpWireFormat.java

示例15: readIncomingMessage

import org.fusesource.hawtbuf.Buffer; //导入依赖的package包/类
protected EncodedMessage readIncomingMessage(Delivery incoming) {
    Buffer buffer;
    int count;

    while ((count = endpoint.recv(incomingBuffer, 0, incomingBuffer.length)) > 0) {
        streamBuffer.write(incomingBuffer, 0, count);
    }

    buffer = streamBuffer.toBuffer();

    try {
        return new EncodedMessage(incoming.getMessageFormat(), buffer.data, buffer.offset, buffer.length);
    } finally {
        streamBuffer.reset();
    }
}
 
开发者ID:fusesource,项目名称:hawtjms,代码行数:17,代码来源:AmqpConsumer.java


注:本文中的org.fusesource.hawtbuf.Buffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。