Skip to content

Commit

Permalink
Added ability to specify start of SOAR
Browse files Browse the repository at this point in the history
Fixes #96
  • Loading branch information
clarisma committed Feb 24, 2023
1 parent eed6e80 commit 80a6bea
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
2 changes: 0 additions & 2 deletions src/main/java/com/clarisma/common/io/PileFile.java
Expand Up @@ -7,8 +7,6 @@

package com.clarisma.common.io;



import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/com/clarisma/common/soar/Archive.java
Expand Up @@ -30,6 +30,7 @@ public class Archive
private Struct header;
private Struct beforeCurrentPage;
private Struct last;
private final int start;
private int pos;
private int pageSpaceRemaining;
private int pageSizeShift = 12;
Expand Down Expand Up @@ -57,6 +58,12 @@ private static class Hole
}
}

public Archive(int start)
{
this.start = start;
}


public Struct header()
{
return header;
Expand All @@ -73,9 +80,8 @@ public void setHeader(Struct header)
this.header = header;
beforeCurrentPage = header;
last = header;
// Skip 4-byte Blob header (Fix for gol-tool#96)
assert header.location() == 4;
pos = header.size() + 4;
header.setLocation(start);
pos = header.size() + start;
pageSpaceRemaining = pageSize-pos;
}

Expand Down Expand Up @@ -151,7 +157,8 @@ public boolean stuffIntoPage(Struct s, int sizeHint, int page)
// TODO
return false;
}


/*
public void writeGzipFile(Path path) throws IOException
{
try(FileOutputStream fout = new FileOutputStream(path.toFile()))
Expand All @@ -175,6 +182,7 @@ public void writeFile(Path path) throws IOException
out.close();
}
}
*/

public void writeSparseFile(Path path) throws IOException
{
Expand All @@ -186,7 +194,7 @@ public void writeSparseFile(Path path) throws IOException
CREATE_NEW,WRITE,SPARSE);
try(OutputStream fout = Channels.newOutputStream(channel))
{
StructOutputStream out = new StructOutputStream(fout);
StructOutputStream out = new StructOutputStream(fout, start);
out.writeChain(header);
out.flush();
fout.flush();
Expand All @@ -200,7 +208,7 @@ public void writeSparseFile(Path path) throws IOException
public void writeToBuffer(ByteBuffer buf, int pos, PbfOutputStream imports) throws IOException
{
StructOutputStream out = new StructOutputStream(
new ByteBufferOutputStream(buf, pos + 4));
new ByteBufferOutputStream(buf, pos + start), start);
// Skip 4-byte blob header (fix for gol-tool#96)
out.setLinks(imports);
out.writeChain(header);
Expand Down
Expand Up @@ -23,10 +23,10 @@ public class StructOutputStream extends OutputStream
private int pos;
private PbfOutputStream links;

public StructOutputStream(OutputStream out)
public StructOutputStream(OutputStream out, int start)
{
this.out = out;
pos = 4; // skip 4-byte blob header (Fix for gol-tool#96)
pos = start; // skip 4-byte blob header (Fix for gol-tool#96)
}

public void setLinks(PbfOutputStream links)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/geodesk/gol/BuildCommand.java
Expand Up @@ -319,7 +319,7 @@ private void prepare() throws Exception

private void createFeatureStore(TileIndexBuilder tib, StringTableBuilder stb) throws IOException
{
Archive archive = new Archive();
Archive archive = new Archive(0);
SFeatureStoreHeader header = new SFeatureStoreHeader(project);
archive.setHeader(header);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/geodesk/gol/compiler/FeatureTile.java
Expand Up @@ -580,7 +580,7 @@ public void build()
indexes[2] = header.areaIndex;
indexes[3] = header.relationIndex;

archive = new Archive();
archive = new Archive(4);
archive.setHeader(header);
new DefaultFeatureLayout(archive)
.indexes(indexes)
Expand Down

0 comments on commit 80a6bea

Please sign in to comment.