001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020package org.apache.isis.core.commons.encoding; 021 022import java.io.DataInputStream; 023import java.io.IOException; 024import java.io.InputStream; 025 026public class DataInputStreamExtended implements DataInputExtended { 027 028 private final DataInputStream dataInputStream; 029 030 public DataInputStreamExtended(final InputStream inputStream) { 031 this.dataInputStream = new DataInputStream(inputStream); 032 } 033 034 @Override 035 public DataInputStream getDataInputStream() { 036 return dataInputStream; 037 } 038 039 // //////////////////////////////////////// 040 // Boolean, Char 041 // //////////////////////////////////////// 042 043 @Override 044 public boolean readBoolean() throws IOException { 045 return FieldType.BOOLEAN.read(this); 046 } 047 048 @Override 049 public boolean[] readBooleans() throws IOException { 050 return FieldType.BOOLEAN_ARRAY.read(this); 051 } 052 053 @Override 054 public char readChar() throws IOException { 055 return FieldType.CHAR.read(this); 056 } 057 058 @Override 059 public char[] readChars() throws IOException { 060 return FieldType.CHAR_ARRAY.read(this); 061 } 062 063 // //////////////////////////////////////// 064 // Integral Numbers 065 // //////////////////////////////////////// 066 067 @Override 068 public byte readByte() throws IOException { 069 return FieldType.BYTE.read(this); 070 } 071 072 @Override 073 public byte[] readBytes() throws IOException { 074 return FieldType.BYTE_ARRAY.read(this); 075 } 076 077 @Override 078 public short readShort() throws IOException { 079 return FieldType.SHORT.read(this); 080 } 081 082 @Override 083 public short[] readShorts() throws IOException { 084 return FieldType.SHORT_ARRAY.read(this); 085 } 086 087 @Override 088 public int readInt() throws IOException { 089 return FieldType.INTEGER.read(this); 090 } 091 092 @Override 093 public int readUnsignedByte() throws IOException { 094 return FieldType.UNSIGNED_BYTE.read(this); 095 } 096 097 @Override 098 public int readUnsignedShort() throws IOException { 099 return FieldType.UNSIGNED_SHORT.read(this); 100 } 101 102 @Override 103 public int[] readInts() throws IOException { 104 return FieldType.INTEGER_ARRAY.read(this); 105 } 106 107 @Override 108 public long readLong() throws IOException { 109 return FieldType.LONG.read(this); 110 } 111 112 @Override 113 public long[] readLongs() throws IOException { 114 return FieldType.LONG_ARRAY.read(this); 115 } 116 117 // //////////////////////////////////////// 118 // Floating Point Numbers 119 // //////////////////////////////////////// 120 121 @Override 122 public float readFloat() throws IOException { 123 return FieldType.FLOAT.read(this); 124 } 125 126 @Override 127 public float[] readFloats() throws IOException { 128 return FieldType.FLOAT_ARRAY.read(this); 129 } 130 131 @Override 132 public double readDouble() throws IOException { 133 return FieldType.DOUBLE.read(this); 134 } 135 136 @Override 137 public double[] readDoubles() throws IOException { 138 return FieldType.DOUBLE_ARRAY.read(this); 139 } 140 141 // //////////////////////////////////////// 142 // Strings 143 // //////////////////////////////////////// 144 145 @Override 146 public String readUTF() throws IOException { 147 return FieldType.STRING.read(this); 148 } 149 150 @Override 151 public String[] readUTFs() throws IOException { 152 return FieldType.STRING_ARRAY.read(this); 153 } 154 155 // //////////////////////////////////////// 156 // Encodable and Serializable 157 // //////////////////////////////////////// 158 159 @Override 160 @SuppressWarnings("unchecked") 161 public <T> T readEncodable(final Class<T> encodableType) throws IOException { 162 return (T) FieldType.ENCODABLE.read(this); 163 } 164 165 @Override 166 public <T> T[] readEncodables(final Class<T> elementType) throws IOException { 167 return FieldType.ENCODABLE_ARRAY.readArray(this, elementType); 168 } 169 170 @Override 171 @SuppressWarnings("unchecked") 172 public <T> T readSerializable(final Class<T> serializableType) throws IOException { 173 return (T) FieldType.SERIALIZABLE.read(this); 174 } 175 176 @Override 177 public <T> T[] readSerializables(final Class<T> elementType) throws IOException { 178 return FieldType.SERIALIZABLE_ARRAY.readArray(this, elementType); 179 } 180 181 // //////////////////////////////////////// 182 // Other 183 // //////////////////////////////////////// 184 185 @Override 186 public void readFully(final byte[] b) throws IOException { 187 dataInputStream.readFully(b); 188 } 189 190 @Override 191 public void readFully(final byte[] b, final int off, final int len) throws IOException { 192 dataInputStream.readFully(b, off, len); 193 } 194 195 @Override 196 @SuppressWarnings("deprecation") 197 public String readLine() throws IOException { 198 return dataInputStream.readLine(); 199 } 200 201 @Override 202 public int skipBytes(final int n) throws IOException { 203 return dataInputStream.skipBytes(n); 204 } 205 206}