Changeset View
Changeset View
Standalone View
Standalone View
java/src/main/java/org/softwareheritage/graph/SwhGraphProperties.java
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | public class SwhGraphProperties { | ||||
public static SwhGraphProperties load(String path) throws IOException { | public static SwhGraphProperties load(String path) throws IOException { | ||||
return new SwhGraphProperties(path, new NodeIdMap(path), new NodeTypesMap(path)); | return new SwhGraphProperties(path, new NodeIdMap(path), new NodeTypesMap(path)); | ||||
} | } | ||||
/** | /** | ||||
* Cleans up resources after use. | * Cleans up resources after use. | ||||
*/ | */ | ||||
public void close() throws IOException { | public void close() throws IOException { | ||||
nodeIdMap.close(); | |||||
edgeLabelNames.close(); | edgeLabelNames.close(); | ||||
} | } | ||||
/** Return the basename of the compressed graph */ | /** Return the basename of the compressed graph */ | ||||
public String getPath() { | public String getPath() { | ||||
return path; | return path; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 181 Lines • ▼ Show 20 Lines | public class SwhGraphProperties { | ||||
/** Load the revision messages, the release messages and the origin URLs */ | /** Load the revision messages, the release messages and the origin URLs */ | ||||
public void loadMessages() throws IOException { | public void loadMessages() throws IOException { | ||||
messageBuffer = loadMappedBytes(path + ".property.message.bin"); | messageBuffer = loadMappedBytes(path + ".property.message.bin"); | ||||
messageOffsets = loadMappedLongs(path + ".property.message.offset.bin"); | messageOffsets = loadMappedLongs(path + ".property.message.offset.bin"); | ||||
} | } | ||||
/** Get the message of the given revision or release node */ | /** Get the message of the given revision or release node */ | ||||
public byte[] getMessage(long nodeId) throws IOException { | public byte[] getMessage(long nodeId) { | ||||
if (messageBuffer == null || messageOffsets == null) { | if (messageBuffer == null || messageOffsets == null) { | ||||
throw new IllegalStateException("Messages not loaded"); | throw new IllegalStateException("Messages not loaded"); | ||||
} | } | ||||
long startOffset = messageOffsets.getLong(nodeId); | long startOffset = messageOffsets.getLong(nodeId); | ||||
if (startOffset == -1) { | if (startOffset == -1) { | ||||
return null; | return null; | ||||
} | } | ||||
return Base64.getDecoder().decode(getLine(messageBuffer, startOffset)); | return Base64.getDecoder().decode(getLine(messageBuffer, startOffset)); | ||||
} | } | ||||
/** Get the URL of the given origin node */ | /** Get the URL of the given origin node */ | ||||
public String getUrl(long nodeId) throws IOException { | public String getUrl(long nodeId) { | ||||
byte[] url = getMessage(nodeId); | byte[] url = getMessage(nodeId); | ||||
return (url != null) ? new String(url) : null; | return (url != null) ? new String(url) : null; | ||||
} | } | ||||
/** Load the release names */ | /** Load the release names */ | ||||
public void loadTagNames() throws IOException { | public void loadTagNames() throws IOException { | ||||
tagNameBuffer = loadMappedBytes(path + ".property.tag_name.bin"); | tagNameBuffer = loadMappedBytes(path + ".property.tag_name.bin"); | ||||
tagNameOffsets = loadMappedLongs(path + ".property.tag_name.offset.bin"); | tagNameOffsets = loadMappedLongs(path + ".property.tag_name.offset.bin"); | ||||
} | } | ||||
/** Get the name of the given release node */ | /** Get the name of the given release node */ | ||||
public byte[] getTagName(long nodeId) throws IOException { | public byte[] getTagName(long nodeId) { | ||||
if (tagNameBuffer == null || tagNameOffsets == null) { | if (tagNameBuffer == null || tagNameOffsets == null) { | ||||
throw new IllegalStateException("Tag names not loaded"); | throw new IllegalStateException("Tag names not loaded"); | ||||
} | } | ||||
long startOffset = tagNameOffsets.getLong(nodeId); | long startOffset = tagNameOffsets.getLong(nodeId); | ||||
if (startOffset == -1) { | if (startOffset == -1) { | ||||
return null; | return null; | ||||
} | } | ||||
return Base64.getDecoder().decode(getLine(tagNameBuffer, startOffset)); | return Base64.getDecoder().decode(getLine(tagNameBuffer, startOffset)); | ||||
Show All 22 Lines |