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

com.javanut.json.encode.NullableAppendableByteWriterWrapper Maven / Gradle / Ivy

Go to download

Ring buffer based queuing utility for applications that require high performance and/or a small footprint. Well suited for embedded and stream based processing.

There is a newer version: 1.1.27
Show newest version
package com.javanut.json.encode;

import com.javanut.pronghorn.util.AppendableByteWriter;

public class NullableAppendableByteWriterWrapper implements AppendableByteWriter {
	
	public boolean wasNull;
	public AppendableByteWriter externalWriter;
	protected boolean needsQuote;

	@Override
	public NullableAppendableByteWriterWrapper append(CharSequence csq) {
	   	if (null !=csq) {
			assert(!wasNull) : "Can not write text after writing a null";
			if (needsQuote) {
				externalWriter.writeByte('"');
				needsQuote = false;
			}
			externalWriter.append(csq);			
		} else {
			wasNull = true;
			needsQuote = false;
		}
		return this;
	}

	@Override
	public NullableAppendableByteWriterWrapper append(CharSequence csq, int start, int end) {
		assert(!wasNull) : "Can not write text after writing a null";
		if (needsQuote) {
			externalWriter.writeByte('"');
			needsQuote = false;
		}
		externalWriter.append(csq,start,end);
		return this;
	}

	@Override
	public NullableAppendableByteWriterWrapper append(char c) {
		assert(!wasNull) : "Can not write text after writing a null";
		if (needsQuote) {
			externalWriter.writeByte('"');
			needsQuote = false;
		}
		externalWriter.append(c);
		return this;
	}

	@Override
	public void write(byte[] b) {
		assert(!wasNull) : "Can not write text after writing a null";
		if (needsQuote) {
			externalWriter.writeByte('"');
			needsQuote = false;
		}
		externalWriter.write(b);
	}

	@Override
	public void write(byte[] b, int pos, int len) {
		assert(!wasNull) : "Can not write text after writing a null";
		if (needsQuote) {
			externalWriter.writeByte('"');
			needsQuote = false;
		}
		externalWriter.write(b,pos,len);
	}

	@Override
	public void writeByte(int asciiChar) {
		assert(!wasNull) : "Can not write text after writing a null";
		if (needsQuote) {
			externalWriter.writeByte('"');
			needsQuote = false;
		}
		externalWriter.writeByte(asciiChar);
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy