List of usage examples for io.vertx.core.buffer Buffer getString
String getString(int start, int end);
From source file:de.openflorian.alarm.AlarmFaxEventMessageCodec.java
License:Open Source License
@Override public AlarmFaxEvent decodeFromWire(int position, Buffer buffer) { // My custom message starting from this *position* of buffer int _pos = position; // Length of JSON int length = buffer.getInt(_pos); String jsonStr = buffer.getString(_pos += 4, _pos += length); JsonObject contentJson = new JsonObject(jsonStr); String fileName = contentJson.getString(JSON_PROPERTY_FILENAME); return new AlarmFaxEvent(new File(fileName)); }
From source file:de.openflorian.alarm.OperationMessageCodec.java
License:Open Source License
@Override public Operation decodeFromWire(int position, Buffer buffer) { // My custom message starting from this *position* of buffer int _pos = position; // Length of JSON int length = buffer.getInt(_pos); String jsonStr = buffer.getString(_pos += 4, _pos += length); Operation o;/*from ww w . j ava2s . c om*/ try { o = Operation.fromJson(jsonStr); return o; } catch (Exception e) { log.error(e.getMessage(), e); throw new RuntimeException(e.getMessage(), e); } }
From source file:eu.rethink.mn.pipeline.PipeRegistry.java
License:Apache License
public PipeRegistry(Vertx vertx, ClusterManager mgr, String domain) { this.domain = domain; this.mgr = mgr; this.eb = vertx.eventBus(); this.eb.registerDefaultCodec(PipeContext.class, new MessageCodec<PipeContext, PipeContext>() { @Override//w w w .j ava2 s . c o m public byte systemCodecID() { return -1; } @Override public String name() { return PipeContext.class.getName(); } @Override public PipeContext transform(PipeContext ctx) { return ctx; } @Override public void encodeToWire(Buffer buffer, PipeContext ctx) { final String msg = ctx.getMessage().toString(); logger.info("encodeToWire: " + msg); buffer.appendString(msg); } @Override public PipeContext decodeFromWire(int pos, Buffer buffer) { final String msg = buffer.getString(0, buffer.length() - 1); logger.info("decodeFromWire: " + msg); return null; //not needed in this architecture } }); this.components = new HashMap<String, IComponent>(); this.sessions = new HashMap<String, PipeSession>(); this.urlSpace = mgr.getSyncMap("urlSpace"); }
From source file:io.fabric8.msg.jnatsd.protocol.ProtocolHelper.java
License:Apache License
public static Map<String, String> parse(Buffer buffer, int start, int end) { Map<String, String> result = new HashMap(); String command = buffer.getString(start, end); command = command.substring(command.indexOf('{') + 1); command = command.substring(0, command.lastIndexOf('}')); String[] parameters = command.split(","); for (String pair : parameters) { pair = pair.trim();//from ww w .j ava 2s.c om String[] parts = pair.split(":", 2); String key = parts[0].trim(); String val = parts[1].trim(); // trim the quotes int lastQuotePos = key.lastIndexOf("\""); key = key.substring(1, lastQuotePos); // bools and numbers may not have quotes. if (val.startsWith("\"")) { lastQuotePos = val.lastIndexOf("\""); val = val.substring(1, lastQuotePos); } result.put(key, val); } return result; }
From source file:io.fabric8.msg.jnatsd.protocol.Sub.java
License:Apache License
public Sub build(Buffer buffer, int start, int end) { String[] splits = buffer.getString(start, end).split("\\s+"); subject = new Address(splits[1]); if (splits.length >= 4) { queueGroup = splits[2];//from w w w .j a v a2 s. c o m sid = Buffer.buffer(splits[3]); } else { sid = Buffer.buffer(splits[2]); } return this; }
From source file:io.fabric8.msg.jnatsd.protocol.UnSub.java
License:Apache License
public UnSub build(Buffer buffer, int start, int end) { String[] splits = buffer.getString(start, end).split("\\s+"); sid = Buffer.buffer(splits[0]); if (splits.length >= 2) { maxMessages = Integer.parseInt(splits[1]); }// w w w . j av a 2 s. co m return this; }
From source file:microservicerx.rx.DistributedObservableCodec.java
@Override public DistributedObservable decodeFromWire(int position, Buffer buffer) { // My custom message starting from this *position* of buffer int _pos = position; // Length of JSON int length = buffer.getInt(_pos); // Get JSON string by it`s length // Jump 4 because getInt() == 4 bytes String jsonStr = buffer.getString(_pos += 4, _pos += length); JsonObject contentJson = new JsonObject(jsonStr); // Get fields String address = contentJson.getString("address"); // We can finally create custom message object return new DistributedObservable(address); }
From source file:org.eclipse.hono.config.KeyLoader.java
License:Open Source License
private void loadPrivateKeyFromFile(final String keyPath) { if (!vertx.fileSystem().existsBlocking(Objects.requireNonNull(keyPath))) { throw new IllegalArgumentException("private key file does not exist"); } else if (AbstractConfig.hasPemFileSuffix(keyPath)) { try {/*from w w w . j ava 2 s . com*/ Buffer buffer = vertx.fileSystem().readFileBlocking(keyPath); String temp = buffer.getString(0, buffer.length()); temp = temp.replaceAll("(-+BEGIN PRIVATE KEY-+\\r?\\n|-+END PRIVATE KEY-+\\r?\\n?)", ""); KeySpec keySpec = new PKCS8EncodedKeySpec(Base64.getMimeDecoder().decode(temp)); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); privateKey = keyFactory.generatePrivate(keySpec); } catch (GeneralSecurityException e) { LOG.error("cannot load private key", e); } } else { LOG.error("unsupported private key file format"); } }
From source file:org.matrixlab.pisces.metastore.core.CustomMessageCodec.java
@Override public CustomMessage decodeFromWire(int position, Buffer buffer) { // My custom message starting from this *position* of buffer int _pos = position; // Length of JSON int length = buffer.getInt(_pos); // Get JSON string by it`s length // Jump 4 because getInt() == 4 bytes String jsonStr = buffer.getString(_pos += 4, _pos += length); JsonObject contentJson = new JsonObject(jsonStr); // Get fields int statusCode = contentJson.getInteger("statusCode"); String resultCode = contentJson.getString("resultCode"); String summary = contentJson.getString("summary"); // We can finally create custom message object return new CustomMessage(statusCode, resultCode, summary); }
From source file:org.mycontroller.standalone.eventbus.MessageStatusCodec.java
License:Apache License
@Override public MessageStatus decodeFromWire(int position, Buffer buffer) { // My custom message starting from this *position* of buffer int _pos = position; // Length of JSON int length = buffer.getInt(_pos); // Get JSON string by it`s length // Jump 4 because getInt() == 4 bytes String jsonStr = buffer.getString(_pos += 4, _pos += length); JsonObject contentJson = new JsonObject(jsonStr); // Get fields MESSAGE_STATUS status = MESSAGE_STATUS.valueOf(contentJson.getString("status")); String message = contentJson.getString("message"); // We can finally create custom message object return MessageStatus.builder().status(status).message(message).build(); }