List of usage examples for io.vertx.core.parsetools RecordParser newDelimited
static RecordParser newDelimited(Buffer delim, ReadStream<Buffer> stream)
From source file:com.github.ithildir.airbot.service.impl.AirNowMeasurementServiceImpl.java
License:Open Source License
private void _initReportingAreaRecords(Handler<AsyncResult<Void>> handler) { HttpRequest<?> httpRequest = _webClient.get(_REPORTING_AREA_URI); RecordParser recordParser = RecordParser.newDelimited("\n", this::_initReportingAreaRecord); httpRequest = httpRequest.as(BodyCodec.pipe(new RecordParserWriteStream(recordParser))); httpRequest.send(asyncResult -> { HttpResponse<?> httpResponse = _handleHttpResponse(asyncResult, handler); if (httpResponse == null) { return; }/*from w ww . jav a2 s . co m*/ _reportingAreaETag = httpResponse.getHeader(HttpHeaders.ETAG.toString()); if (_logger.isInfoEnabled()) { _logger.info("AirNow reporting area records updated with ETag {0}", _reportingAreaETag); } handler.handle(Future.succeededFuture()); }); }
From source file:examples.ParseToolsExamples.java
License:Open Source License
public void recordParserExample1() { final RecordParser parser = RecordParser.newDelimited("\n", h -> { System.out.println(h.toString()); });//w w w.j av a 2s. co m parser.handle(Buffer.buffer("HELLO\nHOW ARE Y")); parser.handle(Buffer.buffer("OU?\nI AM")); parser.handle(Buffer.buffer("DOING OK")); parser.handle(Buffer.buffer("\n")); }
From source file:io.github.bckfnn.ftp.FtpClient.java
License:Apache License
/** * Connect to the server./*from w w w . ja v a2s .c om*/ * @param handler callback handler that is called when the connection is completed. */ public void connect(Handler<AsyncResult<Void>> handler) { next = resp(handler, when("220", c -> { handler.handle(Future.succeededFuture()); })); client = vertx.createNetClient(); client.connect(port, host, res -> { socket = res.result(); if (res.failed()) { handler.handle(Future.failedFuture(res.cause())); } else { RecordParser parser = RecordParser.newDelimited("\n", this::output); socket.handler(parser); } }); }
From source file:io.techcode.logbulk.pipeline.input.SyslogInput.java
License:Open Source License
@Override protected Handler<Buffer> decoder() { // Setup framing String framing = config.getString(CONF_FRAMING); if ("delimited".equals(framing)) { return RecordParser.newDelimited(config.getString(CONF_DELIMITER), this::decode); } else {/*from w w w.j a va2 s . c om*/ return new Handler<Buffer>() { private int pos = 0; private int recordSize = 0; private Buffer buf = Buffer.buffer(); @Override public void handle(Buffer evt) { buf.appendBuffer(evt); // Current length of buffer int len = buf.length() - pos; while (len >= recordSize) { // Attempt to read pos if (recordSize == 0) { while (pos < len) { if ((buf.getByte(pos) & 0xFF) == ' ') { recordSize = Ints.tryParse(buf.getString(0, pos)); pos += 1; len = buf.length() - pos; break; } else { pos += 1; } } } // We don't know length if (recordSize == 0) return; // Parse if (len >= recordSize) { decode(buf.getBuffer(pos, pos + recordSize)); buf = buf.getBuffer(pos + recordSize, buf.length()); pos = 0; recordSize = 0; len = buf.length(); } } } }; } }
From source file:org.etourdot.vertx.marklogic.http.impl.HttpPart.java
License:Open Source License
public HttpPart(Buffer bodyBuffer) { this.buffer = Buffer.buffer(); List<String> headersList = new ArrayList<>(); // We need to extract headers and content from buffer RecordParser parser = RecordParser.newDelimited("\r\n", new Handler<Buffer>() { int pos = 0; boolean startContent = false; @Override/* w w w . j av a 2 s. co m*/ public void handle(Buffer frame) { if (frame.length() == 0) { if (pos > 0) { startContent = true; } } else { if (!startContent) { headersList.add(frame.toString().trim()); } else { buffer.appendBuffer(frame); } } pos++; } }); parser.handle(bodyBuffer); this.headers = new CaseInsensitiveHeaders(); for (String header : headersList) { int offset = header.indexOf(":"); this.headers.add(header.substring(0, offset), header.substring(offset + 1).trim()); } this.contentType = HttpUtils.extractContentType(headers); this.contentDisposition = HttpUtils.extractContentDisposition(headers); }
From source file:org.etourdot.vertx.marklogic.http.impl.response.DefaultMultiPartResponse.java
License:Open Source License
private void extractParts(HttpClientResponse response, ContentType contentType) { final Map<String, List<HttpPart>> parts = new HashMap<>(); RecordParser parser = RecordParser.newDelimited("--" + contentType.getBoundary(), frame -> { if (frame.length() > 0) { HttpPart httpPart = new HttpPart(frame); if (parts.containsKey(httpPart.getDocumentUri())) { List<HttpPart> httpParts = parts.get(httpPart.getDocumentUri()); List<HttpPart> httpParts2 = new ArrayList<>(httpParts); httpParts2.add(httpPart); parts.put(httpPart.getDocumentUri(), httpParts2); } else { parts.put(httpPart.getDocumentUri(), Collections.singletonList(httpPart)); }//from ww w . j a va 2 s . c o m } }); response.bodyHandler(buffer -> { // multipart if (contentType.getBoundary() != null) { parser.handle(buffer); } else { HttpPart httpPart = new HttpPart(buffer, response.headers()); if (httpPart.getDocumentUri() != null) { if (parts.containsKey(httpPart.getDocumentUri())) { List<HttpPart> httpParts = parts.get(httpPart.getDocumentUri()); httpParts.add(httpPart); } else { parts.put(httpPart.getDocumentUri(), Collections.singletonList(httpPart)); } } } this.documents = transformPartToDocument(parts); this.endHandler.handle(this); }); }
From source file:org.hawkular.metrics.clients.ptrans.graphite.GraphiteServer.java
License:Apache License
public GraphiteServer(Configuration configuration) { port = configuration.getGraphitePort(); recordParser = RecordParser.newDelimited("\n", this::handleRecord); }