modify Metadata.class for geometry type #18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
/**
*/
package com.google.code.or.common.glossary;
import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
import com.google.code.or.common.util.CodecUtils;
import com.google.code.or.common.util.MySQLConstants;
import com.google.code.or.common.util.ToStringBuilder;
import com.google.code.or.io.util.XDeserializer;
/**
*
@author Jingqi Xu
*/
public final class Metadata implements Serializable {
//
private static final long serialVersionUID = 4634414541769527837L;
//
private final byte[] type;
private final int[] metadata;
/**
*
*/
public Metadata(byte[] type, int[] metadata) {
this.type = type;
this.metadata = metadata;
}
/**
*
*/
@OverRide
public String toString() {
return new ToStringBuilder(this)
.append("metadata", Arrays.toString(metadata)).toString();
}
/**
*
*/
public byte getType(int column) {
return this.type[column];
}
public int getMetadata(int column) {
return this.metadata[column];
}
/**
*
*/
public static final Metadata valueOf(byte[] type, byte[] data)
throws IOException {
final int[] metadata = new int[type.length];
final XDeserializer d = new XDeserializer(data);
for(int i = 0; i < type.length; i++) {
final int t = CodecUtils.toUnsigned(type[i]);
switch(t) {
case MySQLConstants.TYPE_FLOAT:
case MySQLConstants.TYPE_DOUBLE:
case MySQLConstants.TYPE_TINY_BLOB:
case MySQLConstants.TYPE_BLOB:
case MySQLConstants.TYPE_MEDIUM_BLOB:
case MySQLConstants.TYPE_LONG_BLOB:
case MySQLConstants.TYPE_GEOMETRY:
metadata[i] = d.readInt(1);
break;
case MySQLConstants.TYPE_BIT:
case MySQLConstants.TYPE_VARCHAR:
case MySQLConstants.TYPE_NEWDECIMAL:
metadata[i] = d.readInt(2); // Little-endian
break;
case MySQLConstants.TYPE_SET:
case MySQLConstants.TYPE_ENUM:
case MySQLConstants.TYPE_STRING:
metadata[i] = CodecUtils.toInt(d.readBytes(2), 0, 2); // Big-endian
break;
case MySQLConstants.TYPE_TIME2:
case MySQLConstants.TYPE_DATETIME2:
case MySQLConstants.TYPE_TIMESTAMP2:
metadata[i] = d.readInt(1);
break;
default:
metadata[i] = 0;
}
}
return new Metadata(type, metadata);
}
}