Home
Cloud
Big Data
CI
Install
Samples
Java
Ubuntu
Maven
Archive
Big Data
|
Pail (writing/reading Strings)
References
The POM file (pom.xml)
PailString.java
References
See this page for more details about Pail:
http://deals.manningpublications.com/pail.pdf
The POM file (pom.xml)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>mtitek.pail.string.samples</groupId> <artifactId>mtitek-pail-string-samples</artifactId> <version>1.0.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-common</artifactId> <version>2.7.3</version> </dependency> <dependency> <groupId>com.backtype</groupId> <artifactId>dfs-datastores</artifactId> <version>1.3.6</version> </dependency> </dependencies> </project>
PailString.java
This java class shows how to use the Pail API to write/read String data types values to/from pail.
►
src/main/java/mtitek/pail/string/samples/PailString.java
package mtitek.pail.string.samples; import java.io.IOException; import java.util.UUID; import org.apache.hadoop.fs.Path; import com.backtype.hadoop.pail.Pail; public class PailString { private static final String PAIL_PATH = "/tmp/pail-test/pail-string"; public static void main(String[] args) throws IOException { writeString(); readString(); } private static void writeString() throws IOException { @SuppressWarnings("unchecked") final Pail<String> pail = Pail.create(PailString.PAIL_PATH, false); final Pail<String>.TypedRecordOutputStream typedRecordOutputStream = pail.openWrite(); final String uuid = UUID.randomUUID().toString(); typedRecordOutputStream.writeObject("UUID".getBytes()); typedRecordOutputStream.writeObject(uuid.getBytes()); typedRecordOutputStream.close(); } private static void readString() throws IOException { final Pail<byte[]> bytesPail = new Pail<>(PailString.PAIL_PATH); final Pail<byte[]>.PailIterator localPailIterator = bytesPail.iterator(); while (localPailIterator.hasNext()) { final byte[] bytes = (byte[]) localPailIterator.next(); System.out.println(new String(bytes)); } } }
© 2010-2022
mti
tek