| 1 |
/* |
| 2 |
* |
| 3 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 4 |
* or more contributor license agreements. See the NOTICE file |
| 5 |
* distributed with this work for additional information |
| 6 |
* regarding copyright ownership. The ASF licenses this file |
| 7 |
* to you under the Apache License, Version 2.0 (the |
| 8 |
* "License"); you may not use this file except in compliance |
| 9 |
* with the License. You may obtain a copy of the License at |
| 10 |
* |
| 11 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
* |
| 13 |
* Unless required by applicable law or agreed to in writing, |
| 14 |
* software distributed under the License is distributed on an |
| 15 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 |
* KIND, either express or implied. See the License for the |
| 17 |
* specific language governing permissions and limitations |
| 18 |
* under the License. |
| 19 |
* |
| 20 |
*/ |
| 21 |
package org.apache.qpid.proton.codec; |
| 22 |
|
| 23 |
import java.nio.ByteBuffer; |
| 24 |
import java.nio.charset.StandardCharsets; |
| 25 |
|
| 26 |
public class DroppingWritableBuffer implements WritableBuffer |
| 27 |
{ |
| 28 |
private int _pos = 0; |
| 29 |
|
| 30 |
@Override |
| 31 |
public boolean hasRemaining() |
| 32 |
{ |
| 33 |
return true; |
| 34 |
} |
| 35 |
|
| 36 |
@Override |
| 37 |
public void put(byte b) |
| 38 |
{ |
| 39 |
_pos += 1; |
| 40 |
} |
| 41 |
|
| 42 |
@Override |
| 43 |
public void putFloat(float f) |
| 44 |
{ |
| 45 |
_pos += 4; |
| 46 |
} |
| 47 |
|
| 48 |
@Override |
| 49 |
public void putDouble(double d) |
| 50 |
{ |
| 51 |
_pos += 8; |
| 52 |
} |
| 53 |
|
| 54 |
@Override |
| 55 |
public void put(byte[] src, int offset, int length) |
| 56 |
{ |
| 57 |
_pos += length; |
| 58 |
} |
| 59 |
|
| 60 |
@Override |
| 61 |
public void putShort(short s) |
| 62 |
{ |
| 63 |
_pos += 2; |
| 64 |
} |
| 65 |
|
| 66 |
@Override |
| 67 |
public void putInt(int i) |
| 68 |
{ |
| 69 |
_pos += 4; |
| 70 |
} |
| 71 |
|
| 72 |
@Override |
| 73 |
public void putLong(long l) |
| 74 |
{ |
| 75 |
_pos += 8; |
| 76 |
} |
| 77 |
|
| 78 |
@Override |
| 79 |
public int remaining() |
| 80 |
{ |
| 81 |
return Integer.MAX_VALUE - _pos; |
| 82 |
} |
| 83 |
|
| 84 |
@Override |
| 85 |
public int position() |
| 86 |
{ |
| 87 |
return _pos; |
| 88 |
} |
| 89 |
|
| 90 |
@Override |
| 91 |
public void position(int position) |
| 92 |
{ |
| 93 |
_pos = position; |
| 94 |
} |
| 95 |
|
| 96 |
@Override |
| 97 |
public void put(ByteBuffer payload) |
| 98 |
{ |
| 99 |
_pos += payload.remaining(); |
| 100 |
payload.position(payload.limit()); |
| 101 |
} |
| 102 |
|
| 103 |
@Override |
| 104 |
public int limit() |
| 105 |
{ |
| 106 |
return Integer.MAX_VALUE; |
| 107 |
} |
| 108 |
|
| 109 |
@Override |
| 110 |
public void put(ReadableBuffer payload) |
| 111 |
{ |
| 112 |
_pos += payload.remaining(); |
| 113 |
payload.position(payload.limit()); |
| 114 |
} |
| 115 |
|
| 116 |
@Override |
| 117 |
public void put(String value) |
| 118 |
{ |
| 119 |
_pos += value.getBytes(StandardCharsets.UTF_8).length; |
| 120 |
} |
| 121 |
} |