use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.
the class JSONUtils method formulateJsonForListKeys.
public static String formulateJsonForListKeys(Object[] keys, String fieldName) {
HeapDataOutputStream outputStream = new HeapDataOutputStream(org.apache.geode.internal.Version.CURRENT);
try {
JsonGenerator generator = enableDisableJSONGeneratorFeature(getObjectMapper().getFactory().createGenerator((OutputStream) outputStream, JsonEncoding.UTF8));
generator.writeStartObject();
generator.writeFieldName(fieldName);
JsonWriter.writeObjectArrayAsJson(generator, keys, null);
generator.writeEndObject();
generator.close();
return new String(outputStream.toByteArray());
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
} finally {
outputStream.close();
}
}
use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.
the class JSONUtils method formulateJsonForExistingQuery.
public static String formulateJsonForExistingQuery(String queryId, String oql) {
HeapDataOutputStream outputStream = new HeapDataOutputStream(org.apache.geode.internal.Version.CURRENT);
try {
JsonGenerator generator = enableDisableJSONGeneratorFeature(getObjectMapper().getFactory().createGenerator((OutputStream) outputStream, JsonEncoding.UTF8));
JsonWriter.writeQueryAsJson(generator, queryId, oql);
generator.close();
return new String(outputStream.toByteArray());
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
} finally {
outputStream.close();
}
}
use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.
the class JSONUtils method convertCollectionToJson.
public static String convertCollectionToJson(Collection<Object> collection) throws JSONException {
HeapDataOutputStream outputStream = new HeapDataOutputStream(org.apache.geode.internal.Version.CURRENT);
try {
JsonGenerator generator = enableDisableJSONGeneratorFeature(getObjectMapper().getFactory().createGenerator((OutputStream) outputStream, JsonEncoding.UTF8));
JsonWriter.writeCollectionAsJson(generator, collection);
generator.close();
return new String(outputStream.toByteArray());
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
} finally {
outputStream.close();
}
}
use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.
the class AbstractRegionEntry method checkPdxEquals.
/**
* This method fixes bug 43643
*/
private static boolean checkPdxEquals(PdxInstance pdx, Object obj) {
if (!(obj instanceof PdxInstance)) {
// if we are not readSerialized.
if (obj instanceof CachedDeserializable) {
CachedDeserializable cdObj = (CachedDeserializable) obj;
if (!cdObj.isSerialized()) {
// obj is actually a byte[] which will never be equal to a PdxInstance
return false;
}
Object cdVal = cdObj.getValue();
if (cdVal instanceof byte[]) {
byte[] cdValBytes = (byte[]) cdVal;
PdxInstance pi = InternalDataSerializer.readPdxInstance(cdValBytes, GemFireCacheImpl.getForPdx("Could not check value equality"));
if (pi != null) {
return pi.equals(pdx);
} else {
// since obj is serialized as something other than pdx it must not equal our pdx
return false;
}
} else {
// remove the cd wrapper so that obj is the actual value we want to compare.
obj = cdVal;
}
}
if (obj != null && obj.getClass().getName().equals(pdx.getClassName())) {
InternalCache internalCache = GemFireCacheImpl.getForPdx("Could not access Pdx registry");
if (internalCache != null) {
PdxSerializer pdxSerializer;
if (obj instanceof PdxSerializable) {
pdxSerializer = null;
} else {
pdxSerializer = internalCache.getPdxSerializer();
}
if (pdxSerializer != null || obj instanceof PdxSerializable) {
// try to convert obj to a PdxInstance
HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT);
try {
if (InternalDataSerializer.autoSerialized(obj, hdos) || InternalDataSerializer.writePdx(hdos, internalCache, obj, pdxSerializer)) {
PdxInstance pi = InternalDataSerializer.readPdxInstance(hdos.toByteArray(), internalCache);
if (pi != null) {
obj = pi;
}
}
} catch (IOException | PdxSerializationException ignore) {
// we are not able to convert it so just fall through
}
}
}
}
}
return basicEquals(obj, pdx);
}
use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.
the class FilterPostAuthorization method checkObjectAuth.
private byte[] checkObjectAuth(byte[] serializedObj, boolean isObject) {
if (!isObject) {
return null;
}
ByteArrayInputStream bis = new ByteArrayInputStream(serializedObj);
DataInputStream dis = new DataInputStream(bis);
Object obj;
try {
obj = DataSerializer.readObject(dis);
if (this.logger.finerEnabled()) {
this.logger.finer("FilterPostAuthorization: successfully read object " + "from serialized object: " + obj);
}
} catch (Exception ex) {
this.logger.severe(LocalizedStrings.FilterPostAuthorization_FILTERPOSTAUTHORIZATION_AN_EXCEPTION_WAS_THROWN_WHILE_TRYING_TO_DESERIALIZE, ex);
return null;
}
obj = checkObjectAuth(obj);
if (obj != null) {
HeapDataOutputStream hos = new HeapDataOutputStream(serializedObj.length + 32, Version.CURRENT);
try {
DataSerializer.writeObject(obj, hos);
return hos.toByteArray();
} catch (Exception ex) {
this.logger.severe(LocalizedStrings.FilterPostAuthorization_FILTERPOSTAUTHORIZATION_AN_EXCEPTION_WAS_THROWN_WHILE_TRYING_TO_SERIALIZE, ex);
}
}
return null;
}
Aggregations