1 package com.quadcap.sql.io; 2 3 40 41 import java.io.IOException ; 42 import java.io.ObjectInput ; 43 import java.io.ObjectOutput ; 44 45 51 public class Arrays { 52 public static void writeBytes(ObjectOutput out, byte[] bytes) 53 throws IOException 54 { 55 if (bytes == null) { 56 out.write(0); 57 } else { 58 out.write(1); 59 out.writeInt(bytes.length); 60 out.write(bytes); 61 } 62 } 63 64 public static byte[] readBytes(ObjectInput in) throws IOException { 65 byte[] ret = null; 66 if (in.read() == 1) { 67 ret = new byte[in.readInt()]; 68 in.read(ret); 69 } 70 return ret; 71 } 72 73 public static void writeInts(ObjectOutput out, int[] ints) 74 throws IOException 75 { 76 if (ints == null) { 77 out.write(0); 78 } else { 79 out.write(1); 80 out.writeInt(ints.length); 81 for (int i = 0; i < ints.length; i++) { 82 out.writeInt(ints[i]); 83 } 84 } 85 } 86 87 public static int[] readInts(ObjectInput in) throws IOException { 88 int[] ret = null; 89 if (in.read() == 1) { 90 ret = new int[in.readInt()]; 91 for (int i = 0; i < ret.length; i++) { 92 ret[i] = in.readInt(); 93 } 94 } 95 return ret; 96 } 97 98 public static void writeLongs(ObjectOutput out, long[] arr) 99 throws IOException 100 { 101 if (arr == null) { 102 out.write(0); 103 } else { 104 out.write(1); 105 out.writeInt(arr.length); 106 for (int i = 0; i < arr.length; i++) { 107 out.writeLong(arr[i]); 108 } 109 } 110 } 111 112 public static long[] readLongs(ObjectInput in) throws IOException { 113 long[] ret = null; 114 if (in.read() == 1) { 115 ret = new long[in.readInt()]; 116 for (int i = 0; i < ret.length; i++) { 117 ret[i] = in.readLong(); 118 } 119 } 120 return ret; 121 } 122 123 } 124 | Popular Tags |