-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supports macro-aware transcoding of Ion 1.1 streams.
- Loading branch information
Showing
9 changed files
with
572 additions
and
33 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
69 changes: 69 additions & 0 deletions
69
src/com/amazon/ion/benchmark/IonMeasurableWriteTask_1_1.java
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.amazon.ion.benchmark; | ||
|
||
import com.amazon.ion.MacroAwareIonReader; | ||
import com.amazon.ion.MacroAwareIonWriter; | ||
import com.amazon.ion.impl._Private_IonReaderBuilder; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.function.Consumer; | ||
|
||
/** | ||
* A MeasurableWriteTask for writing data in the Ion 1.1+ format (either text or binary) using input data that is | ||
* also in the Ion 1.1+ format. This ensures encoding directives and macro invocations are preserved, providing | ||
* a more accurate measurement of the write performance of the input. In cases where either the input or the output | ||
* is Ion 1.0, {@link IonMeasurableWriteTask} should be used instead, as encoding directives and macro invocations | ||
* cannot be preserved in that case. | ||
*/ | ||
public class IonMeasurableWriteTask_1_1 extends MeasurableWriteTask<MacroAwareIonWriter> { | ||
|
||
private final IonUtilities.IonWriterSupplier writerBuilder; | ||
|
||
/** | ||
* @param inputPath path to the data to re-write. | ||
* @param options options to use when writing. | ||
* @throws IOException if thrown when handling the options. | ||
*/ | ||
IonMeasurableWriteTask_1_1(Path inputPath, WriteOptionsCombination options) throws IOException { | ||
super(inputPath, options); | ||
if (options.format == Format.ION_TEXT) { | ||
writerBuilder = IonUtilities.newTextWriterSupplier(options); | ||
} else if (options.format == Format.ION_BINARY) { | ||
writerBuilder = IonUtilities.newBinaryWriterSupplier(options); | ||
} else { | ||
throw new IllegalStateException("IonFormatWriter is compatible only with ION_TEXT and ION_BINARY"); | ||
} | ||
} | ||
|
||
@Override | ||
void generateWriteInstructionsDom(Consumer<WriteInstruction<MacroAwareIonWriter>> instructionsSink) { | ||
throw new UnsupportedOperationException("Write benchmarking of Ion 1.1 from the DOM is not yet supported."); | ||
} | ||
|
||
@Override | ||
void generateWriteInstructionsStreaming(Consumer<WriteInstruction<MacroAwareIonWriter>> instructionsSink) throws IOException { | ||
if (options.limit != Integer.MAX_VALUE || options.flushPeriod != null) { | ||
throw new UnsupportedOperationException("Benchmarking Ion 1.1 write using --limit or --ion-flush-period is not yet supported."); | ||
} | ||
// TODO support buildMacroAware from InputStream to avoid having to buffer all bytes. | ||
try ( | ||
MacroAwareIonReader reader = ((_Private_IonReaderBuilder) IonUtilities.newReaderBuilderForInput(options)) | ||
.buildMacroAware(Files.readAllBytes(inputFile.toPath())) | ||
) { | ||
reader.transcodeTo(new RecordingMacroAwareIonWriter(instructionsSink)); | ||
} | ||
} | ||
|
||
@Override | ||
MacroAwareIonWriter newWriter(OutputStream outputStream) throws IOException { | ||
return (MacroAwareIonWriter) writerBuilder.get(outputStream); | ||
} | ||
|
||
@Override | ||
void closeWriter(MacroAwareIonWriter writer) throws IOException { | ||
// Note: this closes the underlying OutputStream. | ||
writer.close(); | ||
} | ||
} |
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
Oops, something went wrong.