|
@@ -48,6 +48,7 @@ import org.iq80.leveldb.*;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.nio.charset.Charset;
|
|
|
import java.util.*;
|
|
|
import java.util.Map.Entry;
|
|
|
import java.util.concurrent.locks.ReentrantLock;
|
|
@@ -120,25 +121,25 @@ public class LeveldbTimelineStore extends AbstractService
|
|
|
@VisibleForTesting
|
|
|
static final String FILENAME = "leveldb-timeline-store.ldb";
|
|
|
|
|
|
- private static final byte[] START_TIME_LOOKUP_PREFIX = "k".getBytes();
|
|
|
- private static final byte[] ENTITY_ENTRY_PREFIX = "e".getBytes();
|
|
|
- private static final byte[] INDEXED_ENTRY_PREFIX = "i".getBytes();
|
|
|
+ private static final byte[] START_TIME_LOOKUP_PREFIX = "k".getBytes(Charset.forName("UTF-8"));
|
|
|
+ private static final byte[] ENTITY_ENTRY_PREFIX = "e".getBytes(Charset.forName("UTF-8"));
|
|
|
+ private static final byte[] INDEXED_ENTRY_PREFIX = "i".getBytes(Charset.forName("UTF-8"));
|
|
|
|
|
|
- private static final byte[] EVENTS_COLUMN = "e".getBytes();
|
|
|
- private static final byte[] PRIMARY_FILTERS_COLUMN = "f".getBytes();
|
|
|
- private static final byte[] OTHER_INFO_COLUMN = "i".getBytes();
|
|
|
- private static final byte[] RELATED_ENTITIES_COLUMN = "r".getBytes();
|
|
|
+ private static final byte[] EVENTS_COLUMN = "e".getBytes(Charset.forName("UTF-8"));
|
|
|
+ private static final byte[] PRIMARY_FILTERS_COLUMN = "f".getBytes(Charset.forName("UTF-8"));
|
|
|
+ private static final byte[] OTHER_INFO_COLUMN = "i".getBytes(Charset.forName("UTF-8"));
|
|
|
+ private static final byte[] RELATED_ENTITIES_COLUMN = "r".getBytes(Charset.forName("UTF-8"));
|
|
|
private static final byte[] INVISIBLE_REVERSE_RELATED_ENTITIES_COLUMN =
|
|
|
- "z".getBytes();
|
|
|
- private static final byte[] DOMAIN_ID_COLUMN = "d".getBytes();
|
|
|
+ "z".getBytes(Charset.forName("UTF-8"));
|
|
|
+ private static final byte[] DOMAIN_ID_COLUMN = "d".getBytes(Charset.forName("UTF-8"));
|
|
|
|
|
|
- private static final byte[] DOMAIN_ENTRY_PREFIX = "d".getBytes();
|
|
|
- private static final byte[] OWNER_LOOKUP_PREFIX = "o".getBytes();
|
|
|
- private static final byte[] DESCRIPTION_COLUMN = "d".getBytes();
|
|
|
- private static final byte[] OWNER_COLUMN = "o".getBytes();
|
|
|
- private static final byte[] READER_COLUMN = "r".getBytes();
|
|
|
- private static final byte[] WRITER_COLUMN = "w".getBytes();
|
|
|
- private static final byte[] TIMESTAMP_COLUMN = "t".getBytes();
|
|
|
+ private static final byte[] DOMAIN_ENTRY_PREFIX = "d".getBytes(Charset.forName("UTF-8"));
|
|
|
+ private static final byte[] OWNER_LOOKUP_PREFIX = "o".getBytes(Charset.forName("UTF-8"));
|
|
|
+ private static final byte[] DESCRIPTION_COLUMN = "d".getBytes(Charset.forName("UTF-8"));
|
|
|
+ private static final byte[] OWNER_COLUMN = "o".getBytes(Charset.forName("UTF-8"));
|
|
|
+ private static final byte[] READER_COLUMN = "r".getBytes(Charset.forName("UTF-8"));
|
|
|
+ private static final byte[] WRITER_COLUMN = "w".getBytes(Charset.forName("UTF-8"));
|
|
|
+ private static final byte[] TIMESTAMP_COLUMN = "t".getBytes(Charset.forName("UTF-8"));
|
|
|
|
|
|
private static final byte[] EMPTY_BYTES = new byte[0];
|
|
|
|
|
@@ -440,7 +441,7 @@ public class LeveldbTimelineStore extends AbstractService
|
|
|
}
|
|
|
} else if (key[prefixlen] == DOMAIN_ID_COLUMN[0]) {
|
|
|
byte[] v = iterator.peekNext().getValue();
|
|
|
- String domainId = new String(v);
|
|
|
+ String domainId = new String(v, Charset.forName("UTF-8"));
|
|
|
entity.setDomainId(domainId);
|
|
|
} else {
|
|
|
if (key[prefixlen] !=
|
|
@@ -790,7 +791,7 @@ public class LeveldbTimelineStore extends AbstractService
|
|
|
if (domainIdBytes == null) {
|
|
|
domainId = TimelineDataManager.DEFAULT_DOMAIN_ID;
|
|
|
} else {
|
|
|
- domainId = new String(domainIdBytes);
|
|
|
+ domainId = new String(domainIdBytes, Charset.forName("UTF-8"));
|
|
|
}
|
|
|
if (!domainId.equals(entity.getDomainId())) {
|
|
|
// in this case the entity will be put, but the relation will be
|
|
@@ -845,9 +846,9 @@ public class LeveldbTimelineStore extends AbstractService
|
|
|
return;
|
|
|
}
|
|
|
} else {
|
|
|
- writeBatch.put(key, entity.getDomainId().getBytes());
|
|
|
+ writeBatch.put(key, entity.getDomainId().getBytes(Charset.forName("UTF-8")));
|
|
|
writePrimaryFilterEntries(writeBatch, primaryFilters, key,
|
|
|
- entity.getDomainId().getBytes());
|
|
|
+ entity.getDomainId().getBytes(Charset.forName("UTF-8")));
|
|
|
}
|
|
|
db.write(writeBatch);
|
|
|
} catch (DBException de) {
|
|
@@ -879,7 +880,7 @@ public class LeveldbTimelineStore extends AbstractService
|
|
|
// This is the new entity, the domain should be the same
|
|
|
byte[] key = createDomainIdKey(relatedEntity.getId(),
|
|
|
relatedEntity.getType(), relatedEntityStartTime);
|
|
|
- db.put(key, entity.getDomainId().getBytes());
|
|
|
+ db.put(key, entity.getDomainId().getBytes(Charset.forName("UTF-8")));
|
|
|
db.put(createRelatedEntityKey(relatedEntity.getId(),
|
|
|
relatedEntity.getType(), relatedEntityStartTime,
|
|
|
entity.getEntityId(), entity.getEntityType()), EMPTY_BYTES);
|
|
@@ -1206,7 +1207,7 @@ public class LeveldbTimelineStore extends AbstractService
|
|
|
* to the end of the array (for parsing other info keys).
|
|
|
*/
|
|
|
private static String parseRemainingKey(byte[] b, int offset) {
|
|
|
- return new String(b, offset, b.length - offset);
|
|
|
+ return new String(b, offset, b.length - offset, Charset.forName("UTF-8"));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1589,8 +1590,10 @@ public class LeveldbTimelineStore extends AbstractService
|
|
|
byte[] ownerLookupEntryKey = createOwnerLookupKey(
|
|
|
domain.getOwner(), domain.getId(), DESCRIPTION_COLUMN);
|
|
|
if (domain.getDescription() != null) {
|
|
|
- writeBatch.put(domainEntryKey, domain.getDescription().getBytes());
|
|
|
- writeBatch.put(ownerLookupEntryKey, domain.getDescription().getBytes());
|
|
|
+ writeBatch.put(domainEntryKey, domain.getDescription().
|
|
|
+ getBytes(Charset.forName("UTF-8")));
|
|
|
+ writeBatch.put(ownerLookupEntryKey, domain.getDescription().
|
|
|
+ getBytes(Charset.forName("UTF-8")));
|
|
|
} else {
|
|
|
writeBatch.put(domainEntryKey, EMPTY_BYTES);
|
|
|
writeBatch.put(ownerLookupEntryKey, EMPTY_BYTES);
|
|
@@ -1601,16 +1604,17 @@ public class LeveldbTimelineStore extends AbstractService
|
|
|
ownerLookupEntryKey = createOwnerLookupKey(
|
|
|
domain.getOwner(), domain.getId(), OWNER_COLUMN);
|
|
|
// Null check for owner is done before
|
|
|
- writeBatch.put(domainEntryKey, domain.getOwner().getBytes());
|
|
|
- writeBatch.put(ownerLookupEntryKey, domain.getOwner().getBytes());
|
|
|
+ writeBatch.put(domainEntryKey, domain.getOwner().getBytes(Charset.forName("UTF-8")));
|
|
|
+ writeBatch.put(ownerLookupEntryKey, domain.getOwner().getBytes(Charset.forName("UTF-8")));
|
|
|
|
|
|
// Write readers
|
|
|
domainEntryKey = createDomainEntryKey(domain.getId(), READER_COLUMN);
|
|
|
ownerLookupEntryKey = createOwnerLookupKey(
|
|
|
domain.getOwner(), domain.getId(), READER_COLUMN);
|
|
|
if (domain.getReaders() != null && domain.getReaders().length() > 0) {
|
|
|
- writeBatch.put(domainEntryKey, domain.getReaders().getBytes());
|
|
|
- writeBatch.put(ownerLookupEntryKey, domain.getReaders().getBytes());
|
|
|
+ writeBatch.put(domainEntryKey, domain.getReaders().getBytes(Charset.forName("UTF-8")));
|
|
|
+ writeBatch.put(ownerLookupEntryKey, domain.getReaders().
|
|
|
+ getBytes(Charset.forName("UTF-8")));
|
|
|
} else {
|
|
|
writeBatch.put(domainEntryKey, EMPTY_BYTES);
|
|
|
writeBatch.put(ownerLookupEntryKey, EMPTY_BYTES);
|
|
@@ -1621,8 +1625,9 @@ public class LeveldbTimelineStore extends AbstractService
|
|
|
ownerLookupEntryKey = createOwnerLookupKey(
|
|
|
domain.getOwner(), domain.getId(), WRITER_COLUMN);
|
|
|
if (domain.getWriters() != null && domain.getWriters().length() > 0) {
|
|
|
- writeBatch.put(domainEntryKey, domain.getWriters().getBytes());
|
|
|
- writeBatch.put(ownerLookupEntryKey, domain.getWriters().getBytes());
|
|
|
+ writeBatch.put(domainEntryKey, domain.getWriters().getBytes(Charset.forName("UTF-8")));
|
|
|
+ writeBatch.put(ownerLookupEntryKey, domain.getWriters().
|
|
|
+ getBytes(Charset.forName("UTF-8")));
|
|
|
} else {
|
|
|
writeBatch.put(domainEntryKey, EMPTY_BYTES);
|
|
|
writeBatch.put(ownerLookupEntryKey, EMPTY_BYTES);
|
|
@@ -1759,13 +1764,13 @@ public class LeveldbTimelineStore extends AbstractService
|
|
|
byte[] value = iterator.peekNext().getValue();
|
|
|
if (value != null && value.length > 0) {
|
|
|
if (key[prefix.length] == DESCRIPTION_COLUMN[0]) {
|
|
|
- domain.setDescription(new String(value));
|
|
|
+ domain.setDescription(new String(value, Charset.forName("UTF-8")));
|
|
|
} else if (key[prefix.length] == OWNER_COLUMN[0]) {
|
|
|
- domain.setOwner(new String(value));
|
|
|
+ domain.setOwner(new String(value, Charset.forName("UTF-8")));
|
|
|
} else if (key[prefix.length] == READER_COLUMN[0]) {
|
|
|
- domain.setReaders(new String(value));
|
|
|
+ domain.setReaders(new String(value, Charset.forName("UTF-8")));
|
|
|
} else if (key[prefix.length] == WRITER_COLUMN[0]) {
|
|
|
- domain.setWriters(new String(value));
|
|
|
+ domain.setWriters(new String(value, Charset.forName("UTF-8")));
|
|
|
} else if (key[prefix.length] == TIMESTAMP_COLUMN[0]) {
|
|
|
domain.setCreatedTime(readReverseOrderedLong(value, 0));
|
|
|
domain.setModifiedTime(readReverseOrderedLong(value, 8));
|