RegisterSign In

API Documentation: Class DataFileUtils

Package: com.mckoi.data

Static utility methods and classes for managing data in a DataFile.

Constructors Summary

DataFileUtils()

Methods Summary

static InputStream asInputStream(DataFile df)
static OutputStream asOutputStream(DataFile df)
static OutputStream asSimpleDifferenceOutputStream(DataFile df)
static DataInputStream asDataInputStream(DataFile df)
static DataOutputStream asDataOutputStream(DataFile df)
static AddressableDataFile getEmptyImmutableDataFile()

Constructor Details

DataFileUtils()

Method Details

static InputStream asInputStream(DataFile df)

Creates an InputStream object wrapped around a DataFile object. This is a simple wrapper around a DataFile object. Any access on the underlying DataFile object while the input stream is in use will lead to undefined behaviour.

Note that this is only intended as a short lived object for reading information from a DataFile.

static OutputStream asOutputStream(DataFile df)

Creates an OutputStream object wrapped around a DataFile object. This is a simple wrapper around a DataFile object. Any access on the underlying DataFile object while the output stream is in use will lead to undefined behaviour. This object overwrites any information stored in the data file past the current position.

Note that this is only intended as a short lived object for writing data to a DataFile.

static OutputStream asSimpleDifferenceOutputStream(DataFile df)

Creates an OutputStream object wrapped around a DataFile object that skips the front part of the file that is already written if the data is the same. For example, if the DataFile currently contains { 1, 7, 3, 1, 5, 0, 9 } and { 1, 7, 3, 1, 2, 2, 2, 5, 0, 9 } is written to the output stream, the actual write will start at the {2, 2, 2, 5, 0, 9 } sequence at index 4. The first 4 bytes are not overwritten.

The purpose of this is to detect and prevent writing to a data file when the content is already the same, or when the start is the same. The implementation is very simple and will not detect sameness past the first matching sequence.

This object acts like a FileOutputStream such that any information stored in the DataFile past the position is overwritten. When the OutputStream is closed the DataFile is truncated to the current position.

static DataInputStream asDataInputStream(DataFile df)

Creates and returns a DataInputStream object wrapped around a DataFile object. Any access on the underlying DataFile object while the input stream is in use will lead to undefined behaviour.

Note that this is only intended as a short lived object for reading information from a DataFile.

static DataOutputStream asDataOutputStream(DataFile df)

Creates and returns a DataOutputStream object wrapped around a DataFile object. Any access on the underlying DataFile object while the output stream is in use will lead to undefined behaviour. This object overwrites any information stored in the data file past the current position.

Note that this is only intended as a short lived object for writing data to a DataFile.

static AddressableDataFile getEmptyImmutableDataFile()

Returns an empty immutable DataFile implementation.

The text on this page is licensed under the Creative Commons Attribution 3.0 License. Java is a registered trademark of Oracle and/or its affiliates.
Mckoi is Copyright © 2000 - 2020 Diehl and Associates, Inc. All rights reserved.