use of de.topobyte.osm4j.pbf.util.BlobHeader in project osm4j-pbf by topobyte.
the class CopyGroupwise method main.
public static void main(String[] args) throws IOException {
if (args.length != 2) {
System.out.println("usage: " + CopyGroupwise.class.getSimpleName() + " <input> <output>");
System.exit(1);
}
InputStream input = new FileInputStream(args[0]);
OutputStream output = new FileOutputStream(args[1]);
DataInputStream data = new DataInputStream(input);
BlockWriter blockWriter = new BlockWriter(output);
while (true) {
try {
BlobHeader header = PbfUtil.parseHeader(data);
Fileformat.Blob blob = PbfUtil.parseBlock(data, header.getDataLength());
String type = header.getType();
if (type.equals(Constants.BLOCK_TYPE_DATA)) {
BlockData blockData = PbfUtil.getBlockData(blob);
Osmformat.PrimitiveBlock primBlock = Osmformat.PrimitiveBlock.parseFrom(blockData.getBlobData());
Osmformat.PrimitiveBlock.Builder builder = Osmformat.PrimitiveBlock.newBuilder();
for (int i = 0; i < primBlock.getPrimitivegroupCount(); i++) {
Osmformat.PrimitiveGroup.Builder groupBuilder = Osmformat.PrimitiveGroup.newBuilder();
Osmformat.PrimitiveGroup group = primBlock.getPrimitivegroup(i);
List<Osmformat.Node> nodes = group.getNodesList();
Osmformat.DenseNodes dense = group.getDense();
List<Osmformat.Way> ways = group.getWaysList();
List<Osmformat.Relation> relations = group.getRelationsList();
groupBuilder.addAllNodes(nodes);
if (group.hasDense()) {
groupBuilder.setDense(dense);
}
groupBuilder.addAllWays(ways);
groupBuilder.addAllRelations(relations);
builder.addPrimitivegroup(groupBuilder.build());
}
builder.setGranularity(primBlock.getGranularity());
builder.setDateGranularity(primBlock.getDateGranularity());
builder.setStringtable(primBlock.getStringtable());
Osmformat.PrimitiveBlock block = builder.build();
ByteString message = block.toByteString();
blockWriter.write(header.getType(), null, blockData.getCompression(), message);
} else if (type.equals(Constants.BLOCK_TYPE_HEADER)) {
blockWriter.write(header.getType(), null, blob);
}
} catch (EOFException eof) {
break;
}
}
output.close();
}
use of de.topobyte.osm4j.pbf.util.BlobHeader in project osm4j-pbf by topobyte.
the class Uncompress method main.
public static void main(String[] args) throws IOException {
if (args.length != 2) {
System.out.println("usage: " + Uncompress.class.getSimpleName() + " <input> <output>");
System.exit(1);
}
InputStream input = new FileInputStream(args[0]);
OutputStream output = new FileOutputStream(args[1]);
DataInputStream data = new DataInputStream(input);
BlockWriter blockWriter = new BlockWriter(output);
while (true) {
try {
BlobHeader header = PbfUtil.parseHeader(data);
Fileformat.Blob blob = PbfUtil.parseBlock(data, header.getDataLength());
BlockData blockData = PbfUtil.getBlockData(blob);
blockWriter.write(header.getType(), null, Compression.NONE, blockData.getBlobData());
} catch (EOFException eof) {
break;
}
}
output.close();
}
use of de.topobyte.osm4j.pbf.util.BlobHeader in project osm4j-pbf by topobyte.
the class CompressDeflate method main.
public static void main(String[] args) throws IOException {
if (args.length != 2) {
System.out.println("usage: " + CompressDeflate.class.getSimpleName() + " <input> <output>");
System.exit(1);
}
InputStream input = new FileInputStream(args[0]);
OutputStream output = new FileOutputStream(args[1]);
DataInputStream data = new DataInputStream(input);
BlockWriter blockWriter = new BlockWriter(output);
while (true) {
try {
BlobHeader header = PbfUtil.parseHeader(data);
Fileformat.Blob blob = PbfUtil.parseBlock(data, header.getDataLength());
BlockData blockData = PbfUtil.getBlockData(blob);
blockWriter.write(header.getType(), null, Compression.DEFLATE, blockData.getBlobData());
} catch (EOFException eof) {
break;
}
}
output.close();
}
use of de.topobyte.osm4j.pbf.util.BlobHeader in project osm4j-pbf by topobyte.
the class CompressLz4 method main.
public static void main(String[] args) throws IOException {
if (args.length != 2) {
System.out.println("usage: " + CompressLz4.class.getSimpleName() + " <input> <output>");
System.exit(1);
}
InputStream input = new FileInputStream(args[0]);
OutputStream output = new FileOutputStream(args[1]);
DataInputStream data = new DataInputStream(input);
BlockWriter blockWriter = new BlockWriter(output);
while (true) {
try {
BlobHeader header = PbfUtil.parseHeader(data);
Fileformat.Blob blob = PbfUtil.parseBlock(data, header.getDataLength());
BlockData blockData = PbfUtil.getBlockData(blob);
blockWriter.write(header.getType(), null, Compression.LZ4, blockData.getBlobData());
} catch (EOFException eof) {
break;
}
}
output.close();
}
use of de.topobyte.osm4j.pbf.util.BlobHeader in project osm4j-pbf by topobyte.
the class PbfFile method buildBlockIndex.
public void buildBlockIndex() throws IOException {
headerBlockInfo = null;
dataBlockInfos.clear();
file.seek(0);
while (true) {
try {
long pos = file.getFilePointer();
int headerSize = file.readInt();
BlobHeader header = PbfUtil.parseHeader(file, headerSize);
file.skipBytes(header.getDataLength());
BlockInfo info = new BlockInfo(pos, headerSize, header.getDataLength());
if (header.getType().equals(Constants.BLOCK_TYPE_DATA)) {
dataBlockInfos.add(info);
} else if (header.getType().equals(Constants.BLOCK_TYPE_HEADER)) {
if (headerBlockInfo == null) {
headerBlockInfo = info;
} else {
throw new IOException("Multiple header blocks");
}
} else {
throw new IOException("invalid PBF block");
}
} catch (EOFException eof) {
break;
}
}
blockIndexInitialized = true;
}
Aggregations