You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

com.github.lonely-lockley:ltsv-parser

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.github.lonely-lockley:ltsv-parser

"A new implementation of ltsv parser. Does not use regular expressions, respects quote and escape characters, can parse data in strict and lenient modes"


Version published
Maintainers
1

Readme

Source

LTSV Parser

Master: Master build Status Dev:Dev build Status Coverage Maven Central License

A new implementation of a small and fast LTSV parser. Compared to making/ltsv4j it:

  • Does not use regular expressions
  • Has flexible configurations
  • Respects quote and escape characters
  • Can parse data in strict and lenient modes

Be careful - this parser instances are stateful and not synchronized!

Usage examples

Parser defaults allow to parse LTSV formatted data in strict mode:

LtsvParser parser = LtsvParser.builder().build();
Iterator<Map<String, String>> entries = parser.parse("city:Moscow\tlat:55.7522\tlon:37.6155", 
    StandardCharsets.UTF_8);
if (entries.hasNext()) {
    Map<String, String> result = entries.next();
    System.out.println(result.toString());
}

If a data is not fully compatible with LTSV it is still possible to parse that line:

LtsvParser parser = LtsvParser.builder().withQuoteChar('`').withKvDelimiter('=').build();
Iterator<Map<String, String>> entries = parser.parse("city=`New York`\tlat=40.6943\tlon=-73.9249", 
    StandardCharsets.UTF_8);

By default parser works in strict mode. It will throw a ParseLtsvException if meets a problem in input data. For example a value without a key like this:

LtsvParser parser = LtsvParser.builder().withQuoteChar('`').withKvDelimiter('=').build();
Iterator<Map<String, String>> entries = parser.parse("city=`New York`\t=40.6943\tlon=-73.9249", 
    StandardCharsets.UTF_8);

You can enable lenient parse mode when building a parser to make it ignore some recoverable errors in input data. In the case above lenient parser returns null key for value 40.6943. Lenient mode tries to do it's best to parse your data, but it is not guaranteed to be parsed correctly. You should test such cases thoroughly.
Parse a FileInputStream:
test.ltsv

city=Moscow lat=55.7522 lon=37.6155
city=`New York` lat=40.6943 lon=-73.9249
city=Berlin lat=52.5218 lon=13.4015
city=London lat=51.5000 lon=-0.1167

Parser.java

InputStream in = new FileInputStream(new File("test.ltsv"));
LtsvParser parser = LtsvParser.builder().withQuoteChar('`').withKvDelimiter('=').build();
Iterator<Map<String, String>> entries = parser.parse(in);
while (entries.hasNext()) {
    Map<String, String> result = entries.next();
    System.out.println(result.toString());
}

LTSV format description

http://ltsv.org/

Adding dependency to project

Gradle
implementation 'com.github.lonely-lockley:ltsv-parser:1.0.0'
Maven
<dependency>
    <groupId>com.github.lonely-lockley</groupId>
    <artifactId>ltsv-parser</artifactId>
    <version>1.0.0</version>
</dependency>

Prerequisites

  • JDK8+

License

Licensed under the Apache License, Version 2.0.

FAQs

Package last updated on 06 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc