@Test public void testCopyToOutputStreamInt() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); int[] data = new int[] {-1, 0, 1}; Array array = Array.factory(DataType.INT, new int[] {3}, data); long bytesCopied = IospHelper.copyToOutputStream(array, bos); assertThat(bytesCopied).isEqualTo(12); IntBuffer buff = ByteBuffer.wrap(bos.toByteArray()).asIntBuffer(); assertThat(buff.get()).isEqualTo(-1); assertThat(buff.get()).isEqualTo(0); assertThat(buff.get()).isEqualTo(1); assertThat(buff.hasRemaining()).isFalse(); }
public static long copyToOutputStream(Array data, OutputStream out) throws java.io.IOException { Class classType = data.getElementType(); DataOutputStream dataOut; if (out instanceof DataOutputStream) dataOut = (DataOutputStream) out; else dataOut = new DataOutputStream(out); IndexIterator iterA = data.getIndexIterator(); if (classType == double.class) { while (iterA.hasNext()) dataOut.writeDouble(iterA.getDoubleNext()); } else if (classType == float.class) { while (iterA.hasNext()) dataOut.writeFloat(iterA.getFloatNext()); } else if (classType == long.class) { while (iterA.hasNext()) dataOut.writeLong(iterA.getLongNext()); } else if (classType == int.class) { while (iterA.hasNext()) dataOut.writeInt(iterA.getIntNext()); } else if (classType == short.class) { while (iterA.hasNext()) dataOut.writeShort(iterA.getShortNext()); } else if (classType == char.class) { byte[] pa = convertCharToByte((char[]) data.get1DJavaArray(DataType.CHAR)); dataOut.write(pa, 0, pa.length); } else if (classType == byte.class) { while (iterA.hasNext()) dataOut.writeByte(iterA.getByteNext()); } else if (classType == boolean.class) { while (iterA.hasNext()) dataOut.writeBoolean(iterA.getBooleanNext()); } else if (classType == String.class) { long size = 0; while (iterA.hasNext()) { String s = (String) iterA.getObjectNext(); size += NcStream.writeString(dataOut, s); } return size; } else if (classType == ByteBuffer.class) { long size = 0; while (iterA.hasNext()) { ByteBuffer bb = (ByteBuffer) iterA.getObjectNext(); size += NcStream.writeByteBuffer(dataOut, bb); } return size; } else if (data instanceof ArrayObject) { long size = 0; while (iterA.hasNext()) { Array row = (Array) iterA.getObjectNext(); ByteBuffer bb = row.getDataAsByteBuffer(); size += NcStream.writeByteBuffer(dataOut, bb); } return size; } else throw new UnsupportedOperationException("Class type = " + classType.getName()); return data.getSizeBytes(); }
IospHelper { public static long copyToOutputStream(Array data, OutputStream out) throws java.io.IOException { Class classType = data.getElementType(); DataOutputStream dataOut; if (out instanceof DataOutputStream) dataOut = (DataOutputStream) out; else dataOut = new DataOutputStream(out); IndexIterator iterA = data.getIndexIterator(); if (classType == double.class) { while (iterA.hasNext()) dataOut.writeDouble(iterA.getDoubleNext()); } else if (classType == float.class) { while (iterA.hasNext()) dataOut.writeFloat(iterA.getFloatNext()); } else if (classType == long.class) { while (iterA.hasNext()) dataOut.writeLong(iterA.getLongNext()); } else if (classType == int.class) { while (iterA.hasNext()) dataOut.writeInt(iterA.getIntNext()); } else if (classType == short.class) { while (iterA.hasNext()) dataOut.writeShort(iterA.getShortNext()); } else if (classType == char.class) { byte[] pa = convertCharToByte((char[]) data.get1DJavaArray(DataType.CHAR)); dataOut.write(pa, 0, pa.length); } else if (classType == byte.class) { while (iterA.hasNext()) dataOut.writeByte(iterA.getByteNext()); } else if (classType == boolean.class) { while (iterA.hasNext()) dataOut.writeBoolean(iterA.getBooleanNext()); } else if (classType == String.class) { long size = 0; while (iterA.hasNext()) { String s = (String) iterA.getObjectNext(); size += NcStream.writeString(dataOut, s); } return size; } else if (classType == ByteBuffer.class) { long size = 0; while (iterA.hasNext()) { ByteBuffer bb = (ByteBuffer) iterA.getObjectNext(); size += NcStream.writeByteBuffer(dataOut, bb); } return size; } else if (data instanceof ArrayObject) { long size = 0; while (iterA.hasNext()) { Array row = (Array) iterA.getObjectNext(); ByteBuffer bb = row.getDataAsByteBuffer(); size += NcStream.writeByteBuffer(dataOut, bb); } return size; } else throw new UnsupportedOperationException("Class type = " + classType.getName()); return data.getSizeBytes(); } }
IospHelper { public static long copyToOutputStream(Array data, OutputStream out) throws java.io.IOException { Class classType = data.getElementType(); DataOutputStream dataOut; if (out instanceof DataOutputStream) dataOut = (DataOutputStream) out; else dataOut = new DataOutputStream(out); IndexIterator iterA = data.getIndexIterator(); if (classType == double.class) { while (iterA.hasNext()) dataOut.writeDouble(iterA.getDoubleNext()); } else if (classType == float.class) { while (iterA.hasNext()) dataOut.writeFloat(iterA.getFloatNext()); } else if (classType == long.class) { while (iterA.hasNext()) dataOut.writeLong(iterA.getLongNext()); } else if (classType == int.class) { while (iterA.hasNext()) dataOut.writeInt(iterA.getIntNext()); } else if (classType == short.class) { while (iterA.hasNext()) dataOut.writeShort(iterA.getShortNext()); } else if (classType == char.class) { byte[] pa = convertCharToByte((char[]) data.get1DJavaArray(DataType.CHAR)); dataOut.write(pa, 0, pa.length); } else if (classType == byte.class) { while (iterA.hasNext()) dataOut.writeByte(iterA.getByteNext()); } else if (classType == boolean.class) { while (iterA.hasNext()) dataOut.writeBoolean(iterA.getBooleanNext()); } else if (classType == String.class) { long size = 0; while (iterA.hasNext()) { String s = (String) iterA.getObjectNext(); size += NcStream.writeString(dataOut, s); } return size; } else if (classType == ByteBuffer.class) { long size = 0; while (iterA.hasNext()) { ByteBuffer bb = (ByteBuffer) iterA.getObjectNext(); size += NcStream.writeByteBuffer(dataOut, bb); } return size; } else if (data instanceof ArrayObject) { long size = 0; while (iterA.hasNext()) { Array row = (Array) iterA.getObjectNext(); ByteBuffer bb = row.getDataAsByteBuffer(); size += NcStream.writeByteBuffer(dataOut, bb); } return size; } else throw new UnsupportedOperationException("Class type = " + classType.getName()); return data.getSizeBytes(); }  }
IospHelper { public static long copyToOutputStream(Array data, OutputStream out) throws java.io.IOException { Class classType = data.getElementType(); DataOutputStream dataOut; if (out instanceof DataOutputStream) dataOut = (DataOutputStream) out; else dataOut = new DataOutputStream(out); IndexIterator iterA = data.getIndexIterator(); if (classType == double.class) { while (iterA.hasNext()) dataOut.writeDouble(iterA.getDoubleNext()); } else if (classType == float.class) { while (iterA.hasNext()) dataOut.writeFloat(iterA.getFloatNext()); } else if (classType == long.class) { while (iterA.hasNext()) dataOut.writeLong(iterA.getLongNext()); } else if (classType == int.class) { while (iterA.hasNext()) dataOut.writeInt(iterA.getIntNext()); } else if (classType == short.class) { while (iterA.hasNext()) dataOut.writeShort(iterA.getShortNext()); } else if (classType == char.class) { byte[] pa = convertCharToByte((char[]) data.get1DJavaArray(DataType.CHAR)); dataOut.write(pa, 0, pa.length); } else if (classType == byte.class) { while (iterA.hasNext()) dataOut.writeByte(iterA.getByteNext()); } else if (classType == boolean.class) { while (iterA.hasNext()) dataOut.writeBoolean(iterA.getBooleanNext()); } else if (classType == String.class) { long size = 0; while (iterA.hasNext()) { String s = (String) iterA.getObjectNext(); size += NcStream.writeString(dataOut, s); } return size; } else if (classType == ByteBuffer.class) { long size = 0; while (iterA.hasNext()) { ByteBuffer bb = (ByteBuffer) iterA.getObjectNext(); size += NcStream.writeByteBuffer(dataOut, bb); } return size; } else if (data instanceof ArrayObject) { long size = 0; while (iterA.hasNext()) { Array row = (Array) iterA.getObjectNext(); ByteBuffer bb = row.getDataAsByteBuffer(); size += NcStream.writeByteBuffer(dataOut, bb); } return size; } else throw new UnsupportedOperationException("Class type = " + classType.getName()); return data.getSizeBytes(); }  static Object readDataFill(RandomAccessFile raf, Layout index, DataType dataType, Object fillValue,
      int byteOrder); static Object readDataFill(RandomAccessFile raf, Layout index, DataType dataType, Object fillValue,
      int byteOrder, boolean convertChar); static Object readData(RandomAccessFile raf, Layout layout, DataType dataType, Object arr, int byteOrder,
      boolean convertChar); static Object readDataFill(PositioningDataInputStream is, Layout index, DataType dataType, Object fillValue); static Object readData(PositioningDataInputStream raf, Layout index, DataType dataType, Object arr); static Object readDataFill(LayoutBB layout, DataType dataType, Object fillValue); static Object readData(LayoutBB layout, DataType dataType, Object arr); static long copyToOutputStream(Array data, OutputStream out); static Object makePrimitiveArray(int size, DataType dataType); static Object makePrimitiveArray(int size, DataType dataType, Object fillValue); static char[] convertByteToCharUTF(byte[] byteArray); static byte[] convertCharToByteUTF(char[] from); static char[] convertByteToChar(byte[] byteArray); static byte[] convertCharToByte(char[] from); static ucar.ma2.Array readSection(ParsedSectionSpec cer); }
IospHelper { public static long copyToOutputStream(Array data, OutputStream out) throws java.io.IOException { Class classType = data.getElementType(); DataOutputStream dataOut; if (out instanceof DataOutputStream) dataOut = (DataOutputStream) out; else dataOut = new DataOutputStream(out); IndexIterator iterA = data.getIndexIterator(); if (classType == double.class) { while (iterA.hasNext()) dataOut.writeDouble(iterA.getDoubleNext()); } else if (classType == float.class) { while (iterA.hasNext()) dataOut.writeFloat(iterA.getFloatNext()); } else if (classType == long.class) { while (iterA.hasNext()) dataOut.writeLong(iterA.getLongNext()); } else if (classType == int.class) { while (iterA.hasNext()) dataOut.writeInt(iterA.getIntNext()); } else if (classType == short.class) { while (iterA.hasNext()) dataOut.writeShort(iterA.getShortNext()); } else if (classType == char.class) { byte[] pa = convertCharToByte((char[]) data.get1DJavaArray(DataType.CHAR)); dataOut.write(pa, 0, pa.length); } else if (classType == byte.class) { while (iterA.hasNext()) dataOut.writeByte(iterA.getByteNext()); } else if (classType == boolean.class) { while (iterA.hasNext()) dataOut.writeBoolean(iterA.getBooleanNext()); } else if (classType == String.class) { long size = 0; while (iterA.hasNext()) { String s = (String) iterA.getObjectNext(); size += NcStream.writeString(dataOut, s); } return size; } else if (classType == ByteBuffer.class) { long size = 0; while (iterA.hasNext()) { ByteBuffer bb = (ByteBuffer) iterA.getObjectNext(); size += NcStream.writeByteBuffer(dataOut, bb); } return size; } else if (data instanceof ArrayObject) { long size = 0; while (iterA.hasNext()) { Array row = (Array) iterA.getObjectNext(); ByteBuffer bb = row.getDataAsByteBuffer(); size += NcStream.writeByteBuffer(dataOut, bb); } return size; } else throw new UnsupportedOperationException("Class type = " + classType.getName()); return data.getSizeBytes(); }  static Object readDataFill(RandomAccessFile raf, Layout index, DataType dataType, Object fillValue,
      int byteOrder); static Object readDataFill(RandomAccessFile raf, Layout index, DataType dataType, Object fillValue,
      int byteOrder, boolean convertChar); static Object readData(RandomAccessFile raf, Layout layout, DataType dataType, Object arr, int byteOrder,
      boolean convertChar); static Object readDataFill(PositioningDataInputStream is, Layout index, DataType dataType, Object fillValue); static Object readData(PositioningDataInputStream raf, Layout index, DataType dataType, Object arr); static Object readDataFill(LayoutBB layout, DataType dataType, Object fillValue); static Object readData(LayoutBB layout, DataType dataType, Object arr); static long copyToOutputStream(Array data, OutputStream out); static Object makePrimitiveArray(int size, DataType dataType); static Object makePrimitiveArray(int size, DataType dataType, Object fillValue); static char[] convertByteToCharUTF(byte[] byteArray); static byte[] convertCharToByteUTF(char[] from); static char[] convertByteToChar(byte[] byteArray); static byte[] convertCharToByte(char[] from); static ucar.ma2.Array readSection(ParsedSectionSpec cer);  }