Coverage Report - org.galagosearch.tupleflow.ArrayOutput
 
Classes in this File Line Coverage Branch Coverage Complexity
ArrayOutput
0%
0/61
0%
0/20
1.474
 
 1  
 // BSD License (http://www.galagosearch.org/license)
 2  
 package org.galagosearch.tupleflow;
 3  
 
 4  
 import java.io.DataOutput;
 5  
 import java.io.IOException;
 6  
 
 7  
 /**
 8  
  *
 9  
  * @author trevor
 10  
  */
 11  
 public class ArrayOutput {
 12  
     DataOutput output;
 13  
 
 14  0
     public ArrayOutput(DataOutput o) {
 15  0
         output = o;
 16  0
     }
 17  
 
 18  
     public DataOutput getDataOutput() {
 19  0
         return output;
 20  
     }
 21  
 
 22  
     public void writeInt(int out) throws IOException {
 23  0
         output.writeInt(out);
 24  0
     }
 25  
 
 26  
     public void writeInts(int[] out) throws IOException {
 27  0
         output.writeInt(out.length);
 28  0
         for (int i = 0; i < out.length; i++) {
 29  0
             output.writeInt(out[i]);
 30  
         }
 31  0
     }
 32  
 
 33  
     public void writeLong(long out) throws IOException {
 34  0
         output.writeLong(out);
 35  0
     }
 36  
 
 37  
     public void writeLongs(long[] out) throws IOException {
 38  0
         output.writeInt(out.length);
 39  0
         for (int i = 0; i < out.length; i++) {
 40  0
             output.writeLong(out[i]);
 41  
         }
 42  0
     }
 43  
 
 44  
     public void writeChar(char out) throws IOException {
 45  0
         output.writeChar(out);
 46  0
     }
 47  
 
 48  
     public void writeChars(char[] out) throws IOException {
 49  0
         output.writeInt(out.length);
 50  0
         for (int i = 0; i < out.length; i++) {
 51  0
             output.writeChar(out[i]);
 52  
         }
 53  0
     }
 54  
 
 55  
     public void writeBoolean(boolean out) throws IOException {
 56  0
         byte b = out ? (byte) 1 : (byte) 0;
 57  0
         output.writeByte(b);
 58  0
     }
 59  
 
 60  
     public void writeByte(byte out) throws IOException {
 61  0
         output.writeByte(out);
 62  0
     }
 63  
 
 64  
     public void writeBytes(byte[] out) throws IOException {
 65  0
         output.writeInt(out.length);
 66  0
         output.write(out);
 67  0
     }
 68  
 
 69  
     public void writeShort(short out) throws IOException {
 70  0
         output.writeShort(out);
 71  0
     }
 72  
 
 73  
     public void writeShorts(short[] out) throws IOException {
 74  0
         output.writeInt(out.length);
 75  0
         for (int i = 0; i < out.length; i++) {
 76  0
             output.writeShort(out[i]);
 77  
         }
 78  0
     }
 79  
 
 80  
     public void writeDouble(double out) throws IOException {
 81  0
         output.writeDouble(out);
 82  0
     }
 83  
 
 84  
     public void writeDoubles(double[] out) throws IOException {
 85  0
         output.writeInt(out.length);
 86  0
         for (int i = 0; i < out.length; i++) {
 87  0
             output.writeDouble(out[i]);
 88  
         }
 89  0
     }
 90  
 
 91  
     public void writeFloat(float out) throws IOException {
 92  0
         output.writeFloat(out);
 93  0
     }
 94  
 
 95  
     public void writeFloats(float[] out) throws IOException {
 96  0
         output.writeInt(out.length);
 97  0
         for (int i = 0; i < out.length; i++) {
 98  0
             output.writeFloat(out[i]);
 99  
         }
 100  0
     }
 101  
 
 102  
     public void writeString(String out) throws IOException {
 103  
         // check to see if there are any UTF-8 chars in here
 104  0
         byte[] bytes = new byte[out.length()];
 105  
 
 106  0
         for (int i = 0; i < out.length(); i++) {
 107  0
             char c = out.charAt(i);
 108  0
             if (c >= 128) {
 109  0
                 bytes = out.getBytes("UTF-8");
 110  0
                 break;
 111  
             } else {
 112  0
                 bytes[i] = (byte) c;
 113  
             }
 114  
         }
 115  
 
 116  0
         writeBytes(bytes);
 117  0
     }
 118  
 
 119  
     public void writeStrings(String[] out) throws IOException {
 120  0
         output.writeInt(out.length);
 121  0
         for (int i = 0; i < out.length; i++) {
 122  0
             writeString(out[i]);
 123  
         }
 124  0
     }
 125  
 }