https://github.com/making/ltsv4j
Labeled Tab Separated Value(http://ltsv.org/) manipulator for Java
https://github.com/making/ltsv4j
Last synced: 12 months ago
JSON representation
Labeled Tab Separated Value(http://ltsv.org/) manipulator for Java
- Host: GitHub
- URL: https://github.com/making/ltsv4j
- Owner: making
- Created: 2013-02-08T02:55:16.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2016-01-15T08:48:43.000Z (over 10 years ago)
- Last Synced: 2025-04-06T07:43:11.133Z (about 1 year ago)
- Language: Java
- Size: 188 KB
- Stars: 18
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
Awesome Lists containing this project
README
# LTSV4J
Labeled Tab Separated Value(http://ltsv.org/) manipulator for Java
This library is inspired by https://metacpan.org/module/Text::LTSV.
## Usage
### simple
Map line = LTSV.parser().parseLine("hoge:foo\tbar:baz\n"); => {"hoge" : "foo", "bar" : "baz"}
String line = LTSV.formatter().formatLine(line) => "hoge:foo\tbar:baz"
Map line = LTSV.parser().ignores("hoge").parseLine("hoge:foo\tbar:baz\n"); => {"bar" : "baz"}
Map line = LTSV.parser().wants("hoge").parseLine("hoge:foo\tbar:baz\n"); => {"hoge" : "foo"}
List> lines = LTSV.parser().parseLines("test.ltsv");
LTSV.formatter.formatLines(lines, "foo.ltsv");
strict mode
Strictly label must be `%x30-39 / %x41-5A / %x61-7A / "_" / "." / "-"`
and field must be `%x01-08 / %x0B / %x0C / %x0E-FF`.
By default, parser does not check this rule. To enable this, use strict() method.
LTSV.parser().strict().parseLine("@@:foo"); => throw LTSVParseException
### iterator
test.ltsv
a:1 b:2 c:3
a:4 b:5 c:6
a:7 b:8 c:9
Iterator interface is available to read ltsv file
try (LTSVIterator iterator = LTSV.parser().iterator("test.ltsv")) {
{
assertThat(iterator.hasNext(), is(true));
Map line = iterator.next();
assertThat(line.get("a"), is("1"));
assertThat(line.get("b"), is("2"));
assertThat(line.get("c"), is("3"));
}
{
assertThat(iterator.hasNext(), is(true));
Map line = iterator.next();
assertThat(line.get("a"), is("4"));
assertThat(line.get("b"), is("5"));
assertThat(line.get("c"), is("6"));
}
{
assertThat(iterator.hasNext(), is(true));
Map line = iterator.next();
assertThat(line.get("a"), is("7"));
assertThat(line.get("b"), is("8"));
assertThat(line.get("c"), is("9"));
}
assertThat(iterator.hasNext(), is(false));
}
Note that `LTSVIterator` must be closed finally. `LTSVIterator` extends `java.lang.AutoCloseable`, so you can use try-with-resources statement supported from Java7.
## Use with Maven
you can get this artifact from Maven Central Repository :)
am.ik.ltsv4j
ltsv4j
0.9.0
## Prerequisites
* JDK7+
## License
Licensed under the Apache License, Version 2.0.