com.googlecode.objectify.impl.translate.ByteArrayTranslatorFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of objectify Show documentation
Show all versions of objectify Show documentation
The simplest convenient interface to the Google App Engine datastore
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);
}
};
}
}