All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.datakernel.aggregation.ChunkIdCodec Maven / Gradle / Ivy

package io.datakernel.aggregation;

import io.datakernel.codec.StructuredCodec;
import io.datakernel.codec.StructuredInput;
import io.datakernel.codec.StructuredOutput;
import io.datakernel.exception.ParseException;

public interface ChunkIdCodec extends StructuredCodec {
	String toFileName(C chunkId);

	C fromFileName(String chunkFileName);

	@Override
	void encode(StructuredOutput out, C value);

	@Override
	C decode(StructuredInput in) throws ParseException;

	static ChunkIdCodec ofLong() {
		return new ChunkIdCodec() {
			@Override
			public String toFileName(Long chunkId) {
				return chunkId.toString();
			}

			@Override
			public Long fromFileName(String chunkFileName) {
				return Long.parseLong(chunkFileName);
			}

			@Override
			public void encode(StructuredOutput out, Long value) {
				out.writeLong(value);
			}

			@Override
			public Long decode(StructuredInput in) throws ParseException {
				return in.readLong();
			}
		};
	}

	static ChunkIdCodec ofString() {
		return new ChunkIdCodec() {
			@Override
			public String toFileName(String chunkId) {
				return chunkId;
			}

			@Override
			public String fromFileName(String chunkFileName) {
				return chunkFileName;
			}

			@Override
			public void encode(StructuredOutput out, String value) {
				out.writeString(value);
			}

			@Override
			public String decode(StructuredInput in) throws ParseException {
				return in.readString();
			}
		};
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy