comparison src/main/java/alice/datasegment/Command.java @ 467:6e304a7a60e7 dispose

remove white space
author sugi
date Sat, 22 Nov 2014 12:08:24 +0900
parents 99e309768ac9
children 7ef0ebb40c9b
comparison
equal deleted inserted replaced
466:268b1280dc18 467:6e304a7a60e7
57 if (cs != null) { 57 if (cs != null) {
58 csName = cs.toString(); 58 csName = cs.toString();
59 } 59 }
60 return this.type + "\t" + key + "\t" + rData + "\tindex=" + index + "\tcs=" + csName; 60 return this.type + "\t" + key + "\t" + rData + "\tindex=" + index + "\tcs=" + csName;
61 } 61 }
62 62
63 /** 63 /**
64 * @return serialized ByteBuffer 64 * @return serialized ByteBuffer
65 */ 65 */
66 public ByteBuffer convert() { 66 public ByteBuffer convert() {
67 ByteBuffer buf = null; 67 ByteBuffer buf = null;
100 if (compressFlag) { 100 if (compressFlag) {
101 data = zip(data); 101 data = zip(data);
102 compressed = true; 102 compressed = true;
103 } 103 }
104 } 104 }
105 105
106 header = msg.write(new CommandMessage(type.id, index, seq, key, false, serialized, compressed)); 106 header = msg.write(new CommandMessage(type.id, index, seq, key, false, serialized, compressed));
107 dataSize = msg.write(data.length); 107 dataSize = msg.write(data.length);
108 buf = ByteBuffer.allocate(header.length+dataSize.length+data.length); 108 buf = ByteBuffer.allocate(header.length+dataSize.length+data.length);
109 buf.put(header); 109 buf.put(header);
110 buf.put(dataSize); 110 buf.put(dataSize);
121 } catch (IOException e) { 121 } catch (IOException e) {
122 e.printStackTrace(); 122 e.printStackTrace();
123 } 123 }
124 return buf; 124 return buf;
125 } 125 }
126 126
127 /** 127 /**
128 * If this flag is true, command isn't send queue. 128 * If this flag is true, command isn't send queue.
129 * command is executed right now. 129 * command is executed right now.
130 * 130 *
131 * @param flag 131 * @param flag
132 */ 132 */
133 133
134 public void setQuickFlag(boolean flag){ 134 public void setQuickFlag(boolean flag){
135 quickFlag = flag; 135 quickFlag = flag;
136 } 136 }
137 137
138 public boolean getQuickFlag(){ 138 public boolean getQuickFlag(){
139 return quickFlag; 139 return quickFlag;
140 } 140 }
141 141
142 /** 142 /**
143 * Before sending Remote DataSegment, DataSegment type is ByteArray. 143 * Before sending Remote DataSegment, DataSegment type is ByteArray.
144 * If this flag true, ByteArray is compressed with ZRLEE(ZRIB) algorithm 144 * If this flag true, ByteArray is compressed with ZRLEE(ZRIB) algorithm
145 * 145 *
146 * @param flag 146 * @param flag
147 */ 147 */
148 148
149 public void setCompressFlag(boolean flag){ 149 public void setCompressFlag(boolean flag){
150 compressFlag = flag; 150 compressFlag = flag;
151 } 151 }
152 152
153 public boolean getCompressFlag(){ 153 public boolean getCompressFlag(){
154 return compressFlag; 154 return compressFlag;
155 } 155 }
156 156
157 public byte[] zip(byte[] input) throws IOException{ 157 public byte[] zip(byte[] input) throws IOException{
158 Deflater deflater = new Deflater(); 158 Deflater deflater = new Deflater();
159 ByteArrayOutputStream os = new ByteArrayOutputStream(); 159 ByteArrayOutputStream os = new ByteArrayOutputStream();
160 DeflaterOutputStream dos = new DeflaterOutputStream(os, deflater); 160 DeflaterOutputStream dos = new DeflaterOutputStream(os, deflater);
161 dos.write(input); 161 dos.write(input);
162 dos.finish(); 162 dos.finish();
163 return os.toByteArray(); 163 return os.toByteArray();
164 } 164 }
165 } 165 }