001/*-------------------------------------------------------------------------+ 002| | 003| Copyright 2005-2011 the ConQAT Project | 004| | 005| Licensed under the Apache License, Version 2.0 (the "License"); | 006| you may not use this file except in compliance with the License. | 007| You may obtain a copy of the License at | 008| | 009| http://www.apache.org/licenses/LICENSE-2.0 | 010| | 011| Unless required by applicable law or agreed to in writing, software | 012| distributed under the License is distributed on an "AS IS" BASIS, | 013| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 014| See the License for the specific language governing permissions and | 015| limitations under the License. | 016+-------------------------------------------------------------------------*/ 017package org.conqat.lib.commons.serialization.classes; 018 019import java.io.DataInputStream; 020import java.io.DataOutputStream; 021import java.io.IOException; 022 023import org.conqat.lib.commons.serialization.SerializedEntityParser; 024import org.conqat.lib.commons.serialization.SerializedEntityPool; 025import org.conqat.lib.commons.serialization.SerializedEntitySerializer; 026 027/** 028 * Field for byte. 029 */ 030public class SerializedByteField extends SerializedPrimitiveFieldBase { 031 032 /** The type code. */ 033 public static final char TYPE_CODE = 'B'; 034 035 /** Constructor. */ 036 public SerializedByteField(String name) { 037 super(name); 038 } 039 040 /** {@inheritDoc} */ 041 @Override 042 public Object readValue(DataInputStream din, SerializedEntityParser parser) throws IOException { 043 return din.readByte(); 044 } 045 046 /** {@inheritDoc} */ 047 @SuppressWarnings("cast") 048 @Override 049 public void writeValue(Object value, SerializedEntityPool pool, DataOutputStream dos, 050 SerializedEntitySerializer serializer) throws IOException { 051 dos.writeByte((int) ensureType(value, Byte.class)); 052 } 053 054 /** {@inheritDoc} */ 055 @Override 056 protected char getTypeCode() { 057 return TYPE_CODE; 058 } 059}