|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| EmptyPacket.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
/**
|
|
| 2 |
*
|
|
| 3 |
* Copyright 2004 Hiram Chirino
|
|
| 4 |
*
|
|
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
| 6 |
* use this file except in compliance with the License. You may obtain a copy of
|
|
| 7 |
* the License at
|
|
| 8 |
*
|
|
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
| 10 |
*
|
|
| 11 |
* Unless required by applicable law or agreed to in writing, software
|
|
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
| 13 |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
| 14 |
* License for the specific language governing permissions and limitations under
|
|
| 15 |
* the License.
|
|
| 16 |
*/
|
|
| 17 |
package org.activeio.packet;
|
|
| 18 |
|
|
| 19 |
import java.io.DataOutput;
|
|
| 20 |
import java.io.IOException;
|
|
| 21 |
import java.io.OutputStream;
|
|
| 22 |
|
|
| 23 |
import org.activeio.Packet;
|
|
| 24 |
|
|
| 25 |
/**
|
|
| 26 |
* Provides a Packet implementation that is directly backed by a <code>byte[0]</code>.
|
|
| 27 |
*
|
|
| 28 |
* @version $Revision$
|
|
| 29 |
*/
|
|
| 30 |
final public class EmptyPacket implements Packet { |
|
| 31 |
|
|
| 32 |
static final public EmptyPacket EMPTY_PACKET = new EmptyPacket(); |
|
| 33 |
static final byte EMPTY_BYTE_ARRAY[] = new byte[]{}; |
|
| 34 |
static final ByteSequence EMPTY_BYTE_SEQUENCE = new ByteSequence(EMPTY_BYTE_ARRAY,0,0); |
|
| 35 |
|
|
| 36 | 0 |
private EmptyPacket() {
|
| 37 |
} |
|
| 38 |
|
|
| 39 | 0 |
public void writeTo(OutputStream out) throws IOException { |
| 40 |
} |
|
| 41 | 0 |
public void writeTo(DataOutput out) throws IOException { |
| 42 |
} |
|
| 43 |
|
|
| 44 | 0 |
public int position() { |
| 45 | 0 |
return 0;
|
| 46 |
} |
|
| 47 |
|
|
| 48 | 0 |
public void position(int position) { |
| 49 |
} |
|
| 50 |
|
|
| 51 | 0 |
public int limit() { |
| 52 | 0 |
return 0;
|
| 53 |
} |
|
| 54 |
|
|
| 55 | 0 |
public void limit(int limit) { |
| 56 |
} |
|
| 57 |
|
|
| 58 | 0 |
public void flip() { |
| 59 |
} |
|
| 60 |
|
|
| 61 | 0 |
public int remaining() { |
| 62 | 0 |
return 0;
|
| 63 |
} |
|
| 64 |
|
|
| 65 | 0 |
public void rewind() { |
| 66 |
} |
|
| 67 |
|
|
| 68 | 0 |
public boolean hasRemaining() { |
| 69 | 0 |
return false; |
| 70 |
} |
|
| 71 |
|
|
| 72 | 0 |
public void clear() { |
| 73 |
} |
|
| 74 |
|
|
| 75 | 0 |
public int capacity() { |
| 76 | 0 |
return 0;
|
| 77 |
} |
|
| 78 |
|
|
| 79 | 0 |
public Packet slice() {
|
| 80 | 0 |
return this; |
| 81 |
} |
|
| 82 |
|
|
| 83 | 0 |
public Packet duplicate() {
|
| 84 | 0 |
return this; |
| 85 |
} |
|
| 86 |
|
|
| 87 | 0 |
public Object duplicate(ClassLoader cl) throws IOException { |
| 88 | 0 |
try {
|
| 89 | 0 |
Class clazz = cl.loadClass(EmptyPacket.class.getName());
|
| 90 | 0 |
return clazz.getField("EMPTY_PACKET").get(null); |
| 91 |
} catch (Throwable e) {
|
|
| 92 | 0 |
throw (IOException)new IOException("Could not duplicate packet in a different classloader: "+e).initCause(e); |
| 93 |
} |
|
| 94 |
} |
|
| 95 |
|
|
| 96 |
/**
|
|
| 97 |
* @see org.activeio.Packet#read()
|
|
| 98 |
*/
|
|
| 99 | 0 |
public int read() { |
| 100 | 0 |
return -1;
|
| 101 |
} |
|
| 102 |
|
|
| 103 |
/**
|
|
| 104 |
* @see org.activeio.Packet#read(byte[], int, int)
|
|
| 105 |
*/
|
|
| 106 | 0 |
public int read(byte[] data, int offset, int length) { |
| 107 | 0 |
return -1;
|
| 108 |
} |
|
| 109 |
|
|
| 110 |
/**
|
|
| 111 |
* @see org.activeio.Packet#write(int)
|
|
| 112 |
*/
|
|
| 113 | 0 |
public boolean write(int data) { |
| 114 | 0 |
return false; |
| 115 |
} |
|
| 116 |
|
|
| 117 |
/**
|
|
| 118 |
* @see org.activeio.Packet#write(byte[], int, int)
|
|
| 119 |
*/
|
|
| 120 | 0 |
public int write(byte[] data, int offset, int length) { |
| 121 | 0 |
return -1;
|
| 122 |
} |
|
| 123 |
|
|
| 124 | 0 |
public ByteSequence asByteSequence() {
|
| 125 | 0 |
return EMPTY_BYTE_SEQUENCE;
|
| 126 |
} |
|
| 127 |
|
|
| 128 | 0 |
public byte[] sliceAsBytes() { |
| 129 | 0 |
return EMPTY_BYTE_ARRAY;
|
| 130 |
} |
|
| 131 |
|
|
| 132 |
/**
|
|
| 133 |
* @param dest
|
|
| 134 |
* @return the number of bytes read into the dest.
|
|
| 135 |
*/
|
|
| 136 | 0 |
public int read(Packet dest) { |
| 137 | 0 |
return -1;
|
| 138 |
} |
|
| 139 |
|
|
| 140 | 0 |
public String toString() {
|
| 141 | 0 |
return "{position="+position()+",limit="+limit()+",capacity="+capacity()+"}"; |
| 142 |
} |
|
| 143 |
|
|
| 144 | 0 |
public Object narrow(Class target) {
|
| 145 | 0 |
if( target.isAssignableFrom(getClass()) ) {
|
| 146 | 0 |
return this; |
| 147 |
} |
|
| 148 | 0 |
return null; |
| 149 |
} |
|
| 150 |
|
|
| 151 | 0 |
public void dispose() { |
| 152 |
} |
|
| 153 |
|
|
| 154 |
} |
|
||||||||||