List of usage examples for org.apache.commons.codec.binary Hex Hex
public Hex()
From source file:org.apache.accumulo.master.tableOps.compact.CompactRange.java
@Override public Repo<Master> call(final long tid, Master env) throws Exception { String zTablePath = Constants.ZROOT + "/" + env.getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_COMPACT_ID; IZooReaderWriter zoo = env.getContext().getZooReaderWriter(); byte[] cid;//from www .java 2 s . c om try { cid = zoo.mutate(zTablePath, null, null, new Mutator() { @Override public byte[] mutate(byte[] currentValue) throws Exception { String cvs = new String(currentValue, UTF_8); String[] tokens = cvs.split(","); long flushID = Long.parseLong(tokens[0]); flushID++; String txidString = String.format("%016x", tid); for (int i = 1; i < tokens.length; i++) { if (tokens[i].startsWith(txidString)) continue; // skip self log.debug("txidString : {}", txidString); log.debug("tokens[{}] : {}", i, tokens[i]); throw new AcceptableThriftTableOperationException(tableId.canonical(), null, TableOperation.COMPACT, TableOperationExceptionType.OTHER, "Another compaction with iterators and/or a compaction strategy is running"); } StringBuilder encodedIterators = new StringBuilder(); if (config != null) { Hex hex = new Hex(); encodedIterators.append(","); encodedIterators.append(txidString); encodedIterators.append("="); encodedIterators.append(new String(hex.encode(config), UTF_8)); } return (Long.toString(flushID) + encodedIterators).getBytes(UTF_8); } }); return new CompactionDriver(Long.parseLong(new String(cid, UTF_8).split(",")[0]), namespaceId, tableId, startRow, endRow); } catch (NoNodeException nne) { throw new AcceptableThriftTableOperationException(tableId.canonical(), null, TableOperation.COMPACT, TableOperationExceptionType.NOTFOUND, null); } }
From source file:org.apache.accumulo.master.tableOps.CompactRange.java
@Override public Repo<Master> call(final long tid, Master environment) throws Exception { String zTablePath = Constants.ZROOT + "/" + environment.getInstance().getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_COMPACT_ID; IZooReaderWriter zoo = ZooReaderWriter.getInstance(); byte[] cid;/* w w w. j a va 2 s .c om*/ try { cid = zoo.mutate(zTablePath, null, null, new Mutator() { @Override public byte[] mutate(byte[] currentValue) throws Exception { String cvs = new String(currentValue, UTF_8); String[] tokens = cvs.split(","); long flushID = Long.parseLong(tokens[0]); flushID++; String txidString = String.format("%016x", tid); for (int i = 1; i < tokens.length; i++) { if (tokens[i].startsWith(txidString)) continue; // skip self log.debug("txidString : " + txidString); log.debug("tokens[" + i + "] : " + tokens[i]); throw new AcceptableThriftTableOperationException(tableId, null, TableOperation.COMPACT, TableOperationExceptionType.OTHER, "Another compaction with iterators and/or a compaction strategy is running"); } StringBuilder encodedIterators = new StringBuilder(); if (config != null) { Hex hex = new Hex(); encodedIterators.append(","); encodedIterators.append(txidString); encodedIterators.append("="); encodedIterators.append(new String(hex.encode(config), UTF_8)); } return (Long.toString(flushID) + encodedIterators).getBytes(UTF_8); } }); return new CompactionDriver(Long.parseLong(new String(cid, UTF_8).split(",")[0]), tableId, startRow, endRow); } catch (NoNodeException nne) { throw new AcceptableThriftTableOperationException(tableId, null, TableOperation.COMPACT, TableOperationExceptionType.NOTFOUND, null); } }
From source file:org.apache.accumulo.server.master.tableOps.CompactionDriver.java
@Override public Repo<Master> call(final long tid, Master environment) throws Exception { String zTablePath = Constants.ZROOT + "/" + HdfsZooInstance.getInstance().getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_COMPACT_ID; IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance(); byte[] cid;//from ww w . jav a2s. co m try { cid = zoo.mutate(zTablePath, null, null, new Mutator() { @Override public byte[] mutate(byte[] currentValue) throws Exception { String cvs = new String(currentValue); String[] tokens = cvs.split(","); long flushID = Long.parseLong(new String(tokens[0])); flushID++; String txidString = String.format("%016x", tid); for (int i = 1; i < tokens.length; i++) { if (tokens[i].startsWith(txidString)) continue; // skip self throw new ThriftTableOperationException(tableId, null, TableOperation.COMPACT, TableOperationExceptionType.OTHER, "Another compaction with iterators is running"); } StringBuilder encodedIterators = new StringBuilder(); if (iterators != null) { Hex hex = new Hex(); encodedIterators.append(","); encodedIterators.append(txidString); encodedIterators.append("="); encodedIterators.append(new String(hex.encode(iterators))); } return ("" + flushID + encodedIterators).getBytes(); } }); return new CompactionDriver(Long.parseLong(new String(cid).split(",")[0]), tableId, startRow, endRow); } catch (NoNodeException nne) { throw new ThriftTableOperationException(tableId, null, TableOperation.COMPACT, TableOperationExceptionType.NOTFOUND, null); } }
From source file:org.apache.accumulo.server.tabletserver.Tablet.java
Pair<Long, List<IteratorSetting>> getCompactionID() throws NoNodeException { try {// w ww . j av a 2 s. c o m String zTablePath = Constants.ZROOT + "/" + HdfsZooInstance.getInstance().getInstanceID() + Constants.ZTABLES + "/" + extent.getTableId() + Constants.ZTABLE_COMPACT_ID; String[] tokens = new String(ZooReaderWriter.getRetryingInstance().getData(zTablePath, null)) .split(","); long compactID = Long.parseLong(tokens[0]); CompactionIterators iters = new CompactionIterators(); if (tokens.length > 1) { Hex hex = new Hex(); ByteArrayInputStream bais = new ByteArrayInputStream( hex.decode(tokens[1].split("=")[1].getBytes())); DataInputStream dis = new DataInputStream(bais); try { iters.readFields(dis); } catch (IOException e) { throw new RuntimeException(e); } KeyExtent ke = new KeyExtent(extent.getTableId(), iters.getEndRow(), iters.getStartRow()); if (!ke.overlaps(extent)) { // only use iterators if compaction range overlaps iters = new CompactionIterators(); } } return new Pair<Long, List<IteratorSetting>>(compactID, iters.getIterators()); } catch (InterruptedException e) { throw new RuntimeException(e); } catch (NumberFormatException nfe) { throw new RuntimeException(nfe); } catch (KeeperException ke) { if (ke instanceof NoNodeException) { throw (NoNodeException) ke; } else { throw new RuntimeException(ke); } } catch (DecoderException e) { throw new RuntimeException(e); } }
From source file:org.apache.accumulo.tserver.tablet.Tablet.java
public Pair<Long, UserCompactionConfig> getCompactionID() throws NoNodeException { try {//from www . ja v a2 s . c om String zTablePath = Constants.ZROOT + "/" + tabletServer.getInstance().getInstanceID() + Constants.ZTABLES + "/" + extent.getTableId() + Constants.ZTABLE_COMPACT_ID; String[] tokens = new String(ZooReaderWriter.getInstance().getData(zTablePath, null), UTF_8).split(","); long compactID = Long.parseLong(tokens[0]); UserCompactionConfig compactionConfig = new UserCompactionConfig(); if (tokens.length > 1) { Hex hex = new Hex(); ByteArrayInputStream bais = new ByteArrayInputStream( hex.decode(tokens[1].split("=")[1].getBytes(UTF_8))); DataInputStream dis = new DataInputStream(bais); try { compactionConfig.readFields(dis); } catch (IOException e) { throw new RuntimeException(e); } KeyExtent ke = new KeyExtent(extent.getTableId(), compactionConfig.getEndRow(), compactionConfig.getStartRow()); if (!ke.overlaps(extent)) { // only use iterators if compaction range overlaps compactionConfig = new UserCompactionConfig(); } } return new Pair<Long, UserCompactionConfig>(compactID, compactionConfig); } catch (InterruptedException e) { throw new RuntimeException(e); } catch (NumberFormatException nfe) { throw new RuntimeException(nfe); } catch (KeeperException ke) { if (ke instanceof NoNodeException) { throw (NoNodeException) ke; } else { throw new RuntimeException(ke); } } catch (DecoderException e) { throw new RuntimeException(e); } }
From source file:org.apache.accumulo.tserver.Tablet.java
Pair<Long, List<IteratorSetting>> getCompactionID() throws NoNodeException { try {/*www. j a v a2 s . c o m*/ String zTablePath = Constants.ZROOT + "/" + HdfsZooInstance.getInstance().getInstanceID() + Constants.ZTABLES + "/" + extent.getTableId() + Constants.ZTABLE_COMPACT_ID; String[] tokens = new String(ZooReaderWriter.getRetryingInstance().getData(zTablePath, null), Constants.UTF8).split(","); long compactID = Long.parseLong(tokens[0]); CompactionIterators iters = new CompactionIterators(); if (tokens.length > 1) { Hex hex = new Hex(); ByteArrayInputStream bais = new ByteArrayInputStream( hex.decode(tokens[1].split("=")[1].getBytes(Constants.UTF8))); DataInputStream dis = new DataInputStream(bais); try { iters.readFields(dis); } catch (IOException e) { throw new RuntimeException(e); } KeyExtent ke = new KeyExtent(extent.getTableId(), iters.getEndRow(), iters.getStartRow()); if (!ke.overlaps(extent)) { // only use iterators if compaction range overlaps iters = new CompactionIterators(); } } return new Pair<Long, List<IteratorSetting>>(compactID, iters.getIterators()); } catch (InterruptedException e) { throw new RuntimeException(e); } catch (NumberFormatException nfe) { throw new RuntimeException(nfe); } catch (KeeperException ke) { if (ke instanceof NoNodeException) { throw (NoNodeException) ke; } else { throw new RuntimeException(ke); } } catch (DecoderException e) { throw new RuntimeException(e); } }
From source file:org.apache.jmeter.protocol.mqtt.client.MqttPublisher.java
public byte[] createPayload(String message, String useTimeStamp, String useNumSeq, String type_value, String format, String charset) throws IOException, NumberFormatException { ByteArrayOutputStream b = new ByteArrayOutputStream(); DataOutputStream d = new DataOutputStream(b); // flags byte flags = 0x00; if ("TRUE".equals(useTimeStamp)) flags |= 0x80;//from w w w .j a v a 2 s . co m if ("TRUE".equals(useNumSeq)) flags |= 0x40; if (MQTTPublisherGui.INT.equals(type_value)) flags |= 0x20; if (MQTTPublisherGui.LONG.equals(type_value)) flags |= 0x10; if (MQTTPublisherGui.FLOAT.equals(type_value)) flags |= 0x08; if (MQTTPublisherGui.DOUBLE.equals(type_value)) flags |= 0x04; if (MQTTPublisherGui.STRING.equals(type_value)) flags |= 0x02; if (!"TEXT".equals(type_value)) { d.writeByte(flags); } // TimeStamp if ("TRUE".equals(useTimeStamp)) { Date date = new java.util.Date(); d.writeLong(date.getTime()); } // Number Sequence if ("TRUE".equals(useNumSeq)) { d.writeInt(numSeq++); } // Value if (MQTTPublisherGui.INT.equals(type_value)) { d.writeInt(Integer.parseInt(message)); } else if (MQTTPublisherGui.LONG.equals(type_value)) { d.writeLong(Long.parseLong(message)); } else if (MQTTPublisherGui.DOUBLE.equals(type_value)) { d.writeDouble(Double.parseDouble(message)); } else if (MQTTPublisherGui.FLOAT.equals(type_value)) { d.writeDouble(Float.parseFloat(message)); } else if (MQTTPublisherGui.STRING.equals(type_value)) { d.write(message.getBytes()); } else if ("TEXT".equals(type_value)) { d.write(message.getBytes()); } // Format: Encoding if (MQTTPublisherGui.BINARY.equals(format)) { BinaryCodec encoder = new BinaryCodec(); return encoder.encode(b.toByteArray()); } else if (MQTTPublisherGui.BASE64.equals(format)) { return Base64.encodeBase64(b.toByteArray()); } else if (MQTTPublisherGui.BINHEX.equals(format)) { Hex encoder = new Hex(); return encoder.encode(b.toByteArray()); } else if (MQTTPublisherGui.PLAIN_TEXT.equals(format)) { String s = new String(b.toByteArray(), charset); return s.getBytes(); } else return b.toByteArray(); }
From source file:org.apache.jmeter.protocol.mqtt.client.MqttPublisher.java
public byte[] createRandomPayload(String Seed, String min, String max, String type_random, String useTimeStamp, String useNumSeq, String type_value, String format, String charset) throws IOException, NumberFormatException { ByteArrayOutputStream b = new ByteArrayOutputStream(); DataOutputStream d = new DataOutputStream(b); // flags byte flags = 0x00; if ("TRUE".equals(useTimeStamp)) flags |= 0x80;/*from w ww . j a va 2 s . co m*/ if ("TRUE".equals(useNumSeq)) flags |= 0x40; if (MQTTPublisherGui.INT.equals(type_value)) flags |= 0x20; if (MQTTPublisherGui.LONG.equals(type_value)) flags |= 0x10; if (MQTTPublisherGui.FLOAT.equals(type_value)) flags |= 0x08; if (MQTTPublisherGui.DOUBLE.equals(type_value)) flags |= 0x04; if (MQTTPublisherGui.STRING.equals(type_value)) flags |= 0x02; if (!"TEXT".equals(type_value)) { d.writeByte(flags); } // TimeStamp if ("TRUE".equals(useTimeStamp)) { Date date = new java.util.Date(); d.writeLong(date.getTime()); } // Number Sequence if ("TRUE".equals(useNumSeq)) { d.writeInt(numSeq++); } // Value if (MQTTPublisherGui.PSEUDO.equals(type_random)) { generator.setSeed(Long.parseLong(Seed)); if (MQTTPublisherGui.INT.equals(type_value)) { d.writeInt( generator.nextInt(Integer.parseInt(max) - Integer.parseInt(min)) + Integer.parseInt(min)); } else if (MQTTPublisherGui.LONG.equals(type_value)) { long Max = Long.parseLong(max); long Min = Long.parseLong(min); d.writeLong((Math.abs(generator.nextLong() % (Max - Min)) + Min)); } else if (MQTTPublisherGui.DOUBLE.equals(type_value)) { double Max = Double.parseDouble(max); double Min = Double.parseDouble(min); d.writeDouble((Min + (Max - Min) * generator.nextDouble())); } else if (MQTTPublisherGui.FLOAT.equals(type_value)) { float Max = Float.parseFloat(max); float Min = Float.parseFloat(min); d.writeFloat((Min + (Max - Min) * generator.nextFloat())); } } else if (MQTTPublisherGui.SECURE.equals(type_random)) { secureGenerator.setSeed(Long.parseLong(Seed)); if (MQTTPublisherGui.INT.equals(type_value)) { d.writeInt(secureGenerator.nextInt(Integer.parseInt(max) - Integer.parseInt(min)) + Integer.parseInt(min)); } else if (MQTTPublisherGui.LONG.equals(type_value)) { long Max = Long.parseLong(max); long Min = Long.parseLong(min); d.writeLong((Math.abs(secureGenerator.nextLong() % (Max - Min)) + Min)); } else if (MQTTPublisherGui.DOUBLE.equals(type_value)) { double Max = Double.parseDouble(max); double Min = Double.parseDouble(min); d.writeDouble((Min + (Max - Min) * secureGenerator.nextDouble())); } else if (MQTTPublisherGui.FLOAT.equals(type_value)) { float Max = Float.parseFloat(max); float Min = Float.parseFloat(min); d.writeFloat((Min + (Max - Min) * secureGenerator.nextFloat())); } } // Format: Encoding if (MQTTPublisherGui.BINARY.equals(format)) { BinaryCodec encoder = new BinaryCodec(); return encoder.encode(b.toByteArray()); } else if (MQTTPublisherGui.BASE64.equals(format)) { return Base64.encodeBase64(b.toByteArray()); } else if (MQTTPublisherGui.BINHEX.equals(format)) { Hex encoder = new Hex(); return encoder.encode(b.toByteArray()); } else if (MQTTPublisherGui.PLAIN_TEXT.equals(format)) { String s = new String(b.toByteArray(), charset); return s.getBytes(); } else return b.toByteArray(); }
From source file:org.apache.jmeter.protocol.mqtt.client.MqttPublisher.java
private byte[] createBigVolume(String useTimeStamp, String useNumberSeq, String format, String charset, String sizeArray) throws IOException, NumberFormatException { ByteArrayOutputStream b = new ByteArrayOutputStream(); DataOutputStream d = new DataOutputStream(b); // flags byte flags = 0x00; if ("TRUE".equals(useTimeStamp)) flags |= 0x80;//from w w w .j a v a 2s .c o m if ("TRUE".equals(useNumberSeq)) flags |= 0x40; d.writeByte(flags); // TimeStamp if ("TRUE".equals(useTimeStamp)) { Date date = new java.util.Date(); d.writeLong(date.getTime()); } // Number Sequence if ("TRUE".equals(useNumberSeq)) { d.writeInt(numSeq++); } int size = Integer.parseInt(sizeArray); byte[] content = new byte[size]; for (int i = 0; i < size; i++) { content[i] = (byte) (i % 10); } d.write(content); // Format: Encoding if (MQTTPublisherGui.BINARY.equals(format)) { BinaryCodec encoder = new BinaryCodec(); return encoder.encode(b.toByteArray()); } else if (MQTTPublisherGui.BASE64.equals(format)) { return Base64.encodeBase64(b.toByteArray()); } else if (MQTTPublisherGui.BINHEX.equals(format)) { Hex encoder = new Hex(); return encoder.encode(b.toByteArray()); } else if (MQTTPublisherGui.PLAIN_TEXT.equals(format)) { String s = new String(b.toByteArray(), charset); return s.getBytes(); } else return b.toByteArray(); }
From source file:org.apache.jmeter.protocol.mqttws.client.MqttPublisher.java
public byte[] createPayload(String message, String useTimeStamp, String useNumSeq, String type_value, String format, String charset) throws IOException, NumberFormatException { ByteArrayOutputStream b = new ByteArrayOutputStream(); DataOutputStream d = new DataOutputStream(b); // flags byte flags = 0x00; if ("TRUE".equals(useTimeStamp)) flags |= 0x80;//ww w. j a va 2 s. co m if ("TRUE".equals(useNumSeq)) flags |= 0x40; if (MQTTPublisherGui.INT.equals(type_value)) flags |= 0x20; if (MQTTPublisherGui.LONG.equals(type_value)) flags |= 0x10; if (MQTTPublisherGui.FLOAT.equals(type_value)) flags |= 0x08; if (MQTTPublisherGui.DOUBLE.equals(type_value)) flags |= 0x04; if (MQTTPublisherGui.STRING.equals(type_value)) flags |= 0x02; if (!"TEXT".equals(type_value)) { d.writeByte(flags); } // TimeStamp if ("TRUE".equals(useTimeStamp)) { Date date = new java.util.Date(); d.writeLong(date.getTime()); } // Number Sequence if ("TRUE".equals(useNumSeq)) { d.writeInt(numSeq++); } // Value if (MQTTPublisherGui.INT.equals(type_value)) { d.writeInt(Integer.parseInt(message)); } else if (MQTTPublisherGui.LONG.equals(type_value)) { d.writeLong(Long.parseLong(message)); } else if (MQTTPublisherGui.DOUBLE.equals(type_value)) { d.writeDouble(Double.parseDouble(message)); } else if (MQTTPublisherGui.FLOAT.equals(type_value)) { d.writeDouble(Float.parseFloat(message)); } else if (MQTTPublisherGui.STRING.equals(type_value)) { d.write(message.getBytes()); } else if ("TEXT".equals(type_value)) { d.write(message.getBytes()); } else if ("TEXT_POOL".equals(type_value)) { String random_message = createRandomMessageFromPool(message); d.write(random_message.getBytes()); } // Format: Encoding if (MQTTPublisherGui.BINARY.equals(format)) { BinaryCodec encoder = new BinaryCodec(); return encoder.encode(b.toByteArray()); } else if (MQTTPublisherGui.BASE64.equals(format)) { return Base64.encodeBase64(b.toByteArray()); } else if (MQTTPublisherGui.BINHEX.equals(format)) { Hex encoder = new Hex(); return encoder.encode(b.toByteArray()); } else if (MQTTPublisherGui.PLAIN_TEXT.equals(format)) { String s = new String(b.toByteArray(), charset); return s.getBytes(); } else return b.toByteArray(); }