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

com.googlecode.objectify.impl.translate.ByteArrayTranslatorFactory Maven / Gradle / Ivy

There is a newer version: 6.1.2
Show newest version
package com.googlecode.objectify.impl.translate;

import com.google.appengine.api.datastore.Blob;
import com.googlecode.objectify.impl.Path;


/**
 * Translates a byte[] to Blob.  Make sure this translator gets registered *before* the normal ArrayTranslator
 * otherwise it won't get used.
 * 
 * @author Jeff Schnitzer 
 */
public class ByteArrayTranslatorFactory extends ValueTranslatorFactory {

	/** The pojo type this factory recognizes */
	private static final Class BYTE_ARRAY_TYPE = byte[].class;

	/**
	 */
	protected ByteArrayTranslatorFactory() {
		super(BYTE_ARRAY_TYPE);
	}

	/* */
	@Override
	protected ValueTranslator createValueTranslator(TypeKey tk, CreateContext ctx, Path path) {
		return new ValueTranslator(Blob.class) {
			@Override
			public byte[] loadValue(Blob node, LoadContext ctx, Path path) throws SkipException {
				return node.getBytes();
			}

			@Override
			public Blob saveValue(byte[] pojo, boolean index, SaveContext ctx, Path path) throws SkipException {
				return new Blob(pojo);
			}
		};
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy