List of usage examples for io.vertx.core.buffer Buffer appendString
@Fluent Buffer appendString(String str);
The buffer will expand as necessary to accommodate any bytes written.
Returns a reference to this so multiple operations can be appended together
From source file:de.braintags.netrelay.RequestUtil.java
License:Open Source License
/** * Clean one value element of the path within one "/". * "/path/2/template.html" - "2" = "/path/template.html" * /*from w ww . jav a 2s .c o m*/ * Logic is: * value, "/" or nothing before or behind * * @param value * the pure value to be removed * @param path * the path to be cleaned * @return the cleaned path * @throws IllegalArgumentException * if element with one "/" before or after the value wasn't found */ public static String cleanPathElement(String value, String path) { String[] elements = path.split("/"); Buffer buffer = Buffer.buffer(path.startsWith("/") ? "/" : ""); boolean added = false; for (String element : elements) { if (element != null && element.hashCode() != 0 && !element.equals(value)) { buffer.appendString(added ? "/" : "").appendString(element); added = true; } } return buffer.appendString(path.endsWith("/") ? "/" : "").toString(); }
From source file:de.braintags.netrelay.templateengine.thymeleaf.ThymeleafTemplateEngineImplBt.java
License:Open Source License
@Override public void render(RoutingContext context, String templateFileName, Handler<AsyncResult<Buffer>> handler) { Buffer buffer = Buffer.buffer(); try {/*ww w .j a va 2 s. c om*/ Map<String, Object> data = new HashMap<>(); data.put("context", context); data.putAll(context.data()); synchronized (this) { templateResolver.setVertx(context.vertx()); final List<Locale> acceptableLocales = context.acceptableLocales(); io.vertx.ext.web.Locale locale; if (acceptableLocales.size() == 0) { locale = io.vertx.ext.web.Locale.create(); } else { // this is the users preferred locale locale = acceptableLocales.get(0); } templateEngine.process(templateFileName, new WebIContext(data, locale), new Writer() { @Override public void write(char[] cbuf, int off, int len) throws IOException { buffer.appendString(new String(cbuf, off, len)); } @Override public void flush() throws IOException { } @Override public void close() throws IOException { } }); } handler.handle(Future.succeededFuture(buffer)); } catch (Exception ex) { handler.handle(Future.failedFuture(ex)); } }
From source file:de.openflorian.alarm.AlarmFaxEventMessageCodec.java
License:Open Source License
@Override public void encodeToWire(Buffer buffer, AlarmFaxEvent event) { JsonObject jsonToEncode = new JsonObject(); jsonToEncode.put(JSON_PROPERTY_FILENAME, event.getResultFile().getAbsolutePath()); // Encode object to string String jsonToStr = jsonToEncode.encode(); // Length of JSON: is NOT characters count int length = jsonToStr.getBytes().length; // Write data into given buffer buffer.appendInt(length);/*w w w. ja v a 2s. com*/ buffer.appendString(jsonToStr); }
From source file:de.openflorian.alarm.OperationMessageCodec.java
License:Open Source License
@Override public void encodeToWire(Buffer buffer, Operation operation) { // Encode object to string String jsonToStr;//from w w w . j a v a 2 s . co m try { jsonToStr = operation.toJson(); // Length of JSON: is NOT characters count int length = jsonToStr.getBytes().length; // Write data into given buffer buffer.appendInt(length); buffer.appendString(jsonToStr); } 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/*www . j a v a2 s.c om*/ 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.AbstractCommand.java
License:Apache License
@Override public Buffer getBuffer() { String str = toString();/*from w w w . j ava 2 s . c o m*/ Buffer buffer = Buffer.buffer(str.length()); buffer.appendString(str); buffer.appendBuffer(CRLF); return buffer; }
From source file:io.fabric8.msg.jnatsd.protocol.Msg.java
License:Apache License
@Override public Buffer getBuffer() { //MSG + space + subject + space + replyTo + space + size + space + payload int sizeHint = 11 + subject.size() + (replyTo != null ? replyTo.length() : 0); if (payload != null) { sizeHint += payload.length();/*from ww w . j a v a 2s. co m*/ } Buffer buffer = Buffer.buffer(sizeHint); buffer.appendString("MSG "); subject.appendToBuffer(buffer); buffer.appendString(" "); buffer.appendBuffer(sid); buffer.appendString(" "); if (replyTo != null) { replyTo.appendTo(buffer); buffer.appendString(" "); } noBytes.appendTo(buffer); buffer.appendBuffer(CRLF); if (payload != null) { payload.appendTo(buffer); } buffer.appendBuffer(CRLF); return buffer; }
From source file:io.techcode.logbulk.pipeline.output.SyslogOutput.java
License:Open Source License
@Override public Handler<JsonObject> encoder() { return data -> { Buffer buf = Buffer.buffer(); // Add facility buf.appendString("<"); String facility = mapping.get(SyslogHeader.FACILITY); String severity = mapping.get(SyslogHeader.SEVERITY); if (mapping.containsKey(SyslogHeader.FACILITY) && mapping.containsKey(SyslogHeader.SEVERITY) && data.containsKey(facility) && data.containsKey(severity)) { int acc = data.getInteger(facility) * 8 + data.getInteger(severity); buf.appendString(String.valueOf(acc)); }//from w ww . j a v a2 s . co m buf.appendString(">1 "); // Add timestamp populate(buf, SyslogHeader.TIMESTAMP, data); // Add hostname populate(buf, SyslogHeader.HOST, data); // Add application populate(buf, SyslogHeader.APPLICATION, data); // Add processus populate(buf, SyslogHeader.PROCESSUS, data); // Add msg id populate(buf, SyslogHeader.ID, data); // Add structured data populate(buf, SyslogHeader.DATA, data); // Add message String message = mapping.get(SyslogHeader.MESSAGE); if (mapping.containsKey(SyslogHeader.MESSAGE)) { if (data.containsKey(message)) { buf.appendString(String.valueOf(data.getValue(message))); } else { try { Json.mapper.writeValue(new ByteBufOutputStream(buf.getByteBuf()), data.getMap()); } catch (Exception e) { throw new EncodeException("Failed to encode as JSON: " + e.getMessage()); } } } getConnection().write(framing(buf)); }; }
From source file:io.techcode.logbulk.pipeline.output.SyslogOutput.java
License:Open Source License
/** * Framing based on buffer./* w w w .jav a 2 s.c om*/ * * @param buf buffer involved. * @return framed buffer. */ private Buffer framing(Buffer buf) { if (delimiter != null) { return buf.appendString(delimiter); } else { return Buffer.buffer().appendString(String.valueOf(buf.length())).appendString(" ").appendBuffer(buf); } }
From source file:io.techcode.logbulk.pipeline.output.SyslogOutput.java
License:Open Source License
/** * Populate header based on data./*from w ww.ja v a2s . c o m*/ * * @param buf buffer to write in. * @param header header to populate. * @param data data involved. */ private void populate(Buffer buf, SyslogHeader header, JsonObject data) { String key = mapping.get(header); if (mapping.containsKey(header) && data.containsKey(key)) { buf.appendString(String.valueOf(data.getValue(key))); buf.appendString(" "); } else { buf.appendString("- "); } }