Пример #1
0
 @Override
 public void write(DataOutputStream out) throws IOException {
   if (length() >= Integer.MAX_VALUE)
     throw new IllegalArgumentException(
         "Length of data buffer can not be >= Integer.MAX_VALUE on output");
   out.writeUTF(allocationMode.name());
   out.writeInt((int) length());
   out.writeUTF(dataType().name());
   if (dataType() == Type.DOUBLE) {
     for (int i = 0; i < length(); i++) out.writeDouble(getDouble(i));
   } else if (dataType() == Type.INT) {
     for (int i = 0; i < length(); i++) out.writeInt(getInt(i));
   } else {
     for (int i = 0; i < length(); i++) out.writeFloat(getFloat(i));
   }
 }
Пример #2
0
 @Override
 public byte[] asBytes() {
   ByteArrayOutputStream bos = new ByteArrayOutputStream();
   DataOutputStream dos = new DataOutputStream(bos);
   if (dataType() == Type.DOUBLE) {
     for (int i = 0; i < length(); i++) {
       try {
         dos.writeDouble(getDouble(i));
       } catch (IOException e) {
         e.printStackTrace();
       }
     }
   } else {
     for (int i = 0; i < length(); i++) {
       try {
         dos.writeFloat(getFloat(i));
       } catch (IOException e) {
         e.printStackTrace();
       }
     }
   }
   return bos.toByteArray();
 }