-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: create TDFs larger than a single segment (#65)
The previous API was logically incorrect and the only reason that we hadn't uncovered it was because we only had payloads that had one segment. Previously we'd write a manifest entry for each segment. Now we return a stream that clients can write into for the payload. So the API changes to ```java var writer = new ZipWriter(out); writer.data("entry one", new byte[] { ... }); try (var out = writer.stream("entry two")) { var fi = new FileInputStream("..."); fi.transferTo(out); } writer.finish(); // write the zip manifest ``` Also change things so that we can handle streams that don't return all of the bytes requested during a given read. Previously we assumed that a read would always return all of the bytes that might be available in a stream. Address #66
- Loading branch information
Showing
8 changed files
with
251 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
package io.opentdf.platform.sdk; | ||
|
||
import java.io.*; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
public class TDFWriter { | ||
private ZipWriter archiveWriter; | ||
private final OutputStream destination; | ||
public static final String TDF_PAYLOAD_FILE_NAME = "0.payload"; | ||
public static final String TDF_MANIFEST_FILE_NAME = "0.manifest.json"; | ||
private final ZipWriter archiveWriter; | ||
|
||
public TDFWriter(OutputStream destination) { | ||
this.destination = destination; | ||
this.archiveWriter = new ZipWriter(); | ||
this.archiveWriter = new ZipWriter(destination); | ||
} | ||
|
||
public void appendManifest(String manifest) { | ||
this.archiveWriter = this.archiveWriter.file(TDF_MANIFEST_FILE_NAME, manifest.getBytes(StandardCharsets.UTF_8)); | ||
public void appendManifest(String manifest) throws IOException { | ||
this.archiveWriter.data(TDF_MANIFEST_FILE_NAME, manifest.getBytes(StandardCharsets.UTF_8)); | ||
} | ||
|
||
public void appendPayload(byte[] data) { | ||
this.archiveWriter = this.archiveWriter.file(TDF_PAYLOAD_FILE_NAME, data); | ||
public OutputStream payload() throws IOException { | ||
return this.archiveWriter.stream(TDF_PAYLOAD_FILE_NAME); | ||
|
||
} | ||
|
||
public long finish() throws IOException { | ||
return this.archiveWriter.build(this.destination); | ||
return this.archiveWriter.finish(); | ||
} | ||
} |
Oops, something went wrong.