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

io.activej.fs._FileMetadata_DslJsonConverter Maven / Gradle / Ivy

Go to download

Provides tools for building efficient, scalable local, remote or clustered file servers. It utilizes ActiveJ CSP for fast and reliable file transfer.

There is a newer version: 6.0-beta2
Show newest version
package io.activej.fs;



public class _FileMetadata_DslJsonConverter implements com.dslplatform.json.Configuration {
	private static final java.nio.charset.Charset utf8 = java.nio.charset.Charset.forName("UTF-8");
	@Override
	public void configure(com.dslplatform.json.DslJson __dsljson) {
		ObjectFormatConverter objectConverter = new ObjectFormatConverter(__dsljson);
		__dsljson.registerReader(io.activej.fs.FileMetadata.class, objectConverter);
		__dsljson.registerWriter(io.activej.fs.FileMetadata.class, objectConverter);
	}
	public final static class ObjectFormatConverter implements com.dslplatform.json.runtime.FormatConverter {
		private final boolean alwaysSerialize;
		private final com.dslplatform.json.DslJson __dsljson;
		public ObjectFormatConverter(com.dslplatform.json.DslJson __dsljson) {
			this.alwaysSerialize = !__dsljson.omitDefaults;
			this.__dsljson = __dsljson;
		}
		private static final byte[] quoted_size = "\"size\":".getBytes(utf8);
		private static final byte[] name_size = "size".getBytes(utf8);
		private static final byte[] quoted_timestamp = ",\"timestamp\":".getBytes(utf8);
		private static final byte[] name_timestamp = "timestamp".getBytes(utf8);
		public final void write(final com.dslplatform.json.JsonWriter writer, final io.activej.fs.FileMetadata instance) {
			if (instance == null) writer.writeNull();
			else {
				writer.writeByte((byte)'{');
				if (alwaysSerialize) { writeContentFull(writer, instance); writer.writeByte((byte)'}'); }
				else if (writeContentMinimal(writer, instance)) writer.getByteBuffer()[writer.size() - 1] = '}';
				else writer.writeByte((byte)'}');
			}
		}
		public void writeContentFull(final com.dslplatform.json.JsonWriter writer, final io.activej.fs.FileMetadata instance) {
			writer.writeAscii(quoted_size);
			com.dslplatform.json.NumberConverter.serialize(instance.getSize(), writer);
			writer.writeAscii(quoted_timestamp);
			com.dslplatform.json.NumberConverter.serialize(instance.getTimestamp(), writer);
		}
		public boolean writeContentMinimal(final com.dslplatform.json.JsonWriter writer, final io.activej.fs.FileMetadata instance) {
			boolean hasWritten = false;
			if (instance.getSize() != 0L) {
				writer.writeByte((byte)'"'); writer.writeAscii(name_size); writer.writeByte((byte)'"'); writer.writeByte((byte)':');
				com.dslplatform.json.NumberConverter.serialize(instance.getSize(), writer);
				writer.writeByte((byte)','); hasWritten = true;
			}
			if (instance.getTimestamp() != 0L) {
				writer.writeByte((byte)'"'); writer.writeAscii(name_timestamp); writer.writeByte((byte)'"'); writer.writeByte((byte)':');
				com.dslplatform.json.NumberConverter.serialize(instance.getTimestamp(), writer);
				writer.writeByte((byte)','); hasWritten = true;
			}
			return hasWritten;
		}
		public io.activej.fs.FileMetadata read(final com.dslplatform.json.JsonReader reader) throws java.io.IOException {
			if (reader.wasNull()) return null;
			else if (reader.last() != '{') throw reader.newParseError("Expecting '{' for object start");
			reader.getNextToken();
			return readContent(reader);
		}
		public io.activej.fs.FileMetadata readContent(final com.dslplatform.json.JsonReader reader) throws java.io.IOException {
			long _size_ = 0L;
			long _timestamp_ = 0L;
			if (reader.last() == '}') {
				return io.activej.fs.FileMetadata.of(_size_, _timestamp_);
			}
			switch(reader.fillName()) {
				case 597743964:
					reader.getNextToken();
					_size_ = com.dslplatform.json.NumberConverter.deserializeLong(reader);
					reader.getNextToken();
					break;
				case -1299983069:
					reader.getNextToken();
					_timestamp_ = com.dslplatform.json.NumberConverter.deserializeLong(reader);
					reader.getNextToken();
					break;
				default:
					reader.getNextToken();
					reader.skip();
			}
			while (reader.last() == ','){
				reader.getNextToken();
				switch(reader.fillName()) {
					case 597743964:
						reader.getNextToken();
						_size_ = com.dslplatform.json.NumberConverter.deserializeLong(reader);
						reader.getNextToken();
						break;
					case -1299983069:
						reader.getNextToken();
						_timestamp_ = com.dslplatform.json.NumberConverter.deserializeLong(reader);
						reader.getNextToken();
						break;
					default:
						reader.getNextToken();
						reader.skip();
				}
			}
			if (reader.last() != '}') throw reader.newParseError("Expecting '}' for object end");
			return io.activej.fs.FileMetadata.of(_size_, _timestamp_);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy