Skip to content

Commit

Permalink
Merge pull request #434 from pmpowers-usgs/export-update
Browse files Browse the repository at this point in the history
fixed binary export
  • Loading branch information
pmpowers-usgs authored Jul 16, 2019
2 parents 33fdb0e + fb10ed4 commit 4a1dbce
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/gov/usgs/earthquake/nshmp/calc/HazardExport.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
import static gov.usgs.earthquake.nshmp.data.XySequence.emptyCopyOf;
import static java.nio.ByteOrder.LITTLE_ENDIAN;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.StandardOpenOption.APPEND;
import static java.nio.file.StandardOpenOption.CREATE;
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
import static java.nio.file.StandardOpenOption.WRITE;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.sql.Timestamp;
import java.util.EnumMap;
import java.util.List;
Expand Down Expand Up @@ -161,7 +164,6 @@ private void init(Sites sites) throws IOException {
}
}


for (Imt imt : config.hazard.imts) {

Path imtDir = dir.resolve(imt.name());
Expand Down Expand Up @@ -324,7 +326,7 @@ private void writeHazard(Hazard hazard) throws IOException {
String totalLine = toLine(locData, totalCurve.yValues(), valueFormatter);

Path totalFile = imtDir.resolve(CURVE_FILE_ASCII);
writeLine(totalFile, totalLine, StandardOpenOption.APPEND);
writeLine(totalFile, totalLine, APPEND);

Metadata meta = null;
int binIndex = -1;
Expand All @@ -350,7 +352,7 @@ private void writeHazard(Hazard hazard) throws IOException {
writeBinary(typeBinFile, meta, typeCurve, binIndex);
}
}
writeLine(typeFile, typeLine, StandardOpenOption.APPEND);
writeLine(typeFile, typeLine, APPEND);
}
}

Expand All @@ -369,7 +371,7 @@ private void writeHazard(Hazard hazard) throws IOException {
writeBinary(gmmBinFile, meta, gmmCurve, binIndex);
}
}
writeLine(gmmFile, gmmLine, StandardOpenOption.APPEND);
writeLine(gmmFile, gmmLine, APPEND);
}
}
}
Expand Down Expand Up @@ -666,7 +668,7 @@ private void writeBinary(
Metadata meta,
XySequence curve,
int curveIndex) throws IOException {
FileChannel channel = FileChannel.open(path, StandardOpenOption.WRITE);
FileChannel channel = FileChannel.open(path, WRITE);
int position = HEADER_OFFSET + curveIndex * meta.curveByteSize;
toBuffer(curve, meta.buffer);
channel.write(meta.buffer, position);
Expand All @@ -682,7 +684,7 @@ private static void toBuffer(XySequence curve, ByteBuffer buffer) {
}

private void initBinary(Path path, Metadata meta) throws IOException {
FileChannel channel = FileChannel.open(path, StandardOpenOption.WRITE);
FileChannel channel = FileChannel.open(path, CREATE, TRUNCATE_EXISTING, WRITE);
ByteBuffer header = createHeader(meta);
header.flip();
channel.write(header);
Expand Down

0 comments on commit 4a1dbce

Please sign in to comment.