private int getNamespaceID(String namespace, boolean create) throws IOException { Integer cacheID = namespaceIDCache.get(namespace); if (cacheID != null) { return cacheID.intValue(); } byte[] namespaceData = namespace.getBytes("UTF-8"); int id; if (create) { id = dataStore.storeData(namespaceData); } else { id = dataStore.getID(namespaceData); } if (id != -1) { namespaceIDCache.put(namespace, new Integer(id)); } return id; }
private int getNamespaceID(String namespace, boolean create) throws IOException { Integer cacheID = namespaceIDCache.get(namespace); if (cacheID != null) { return cacheID.intValue(); } byte[] namespaceData = namespace.getBytes("UTF-8"); int id; if (create) { id = dataStore.storeData(namespaceData); } else { id = dataStore.getID(namespaceData); } if (id != -1) { namespaceIDCache.put(namespace, new Integer(id)); } return id; }
/** * Stores the supplied value and returns the ID that has been assigned to it. In case the data to store is * already present, the ID of this existing data is returned. * * @param data * The data to store, must not be <tt>null</tt>. * @return The ID that has been assigned to the value. * @exception IOException * If an I/O error occurred. */ public int storeData(byte[] data) throws IOException { assert data != null : "data must not be null"; int id = getID(data); if (id == -1) { // Data not stored yet, store it under a new ID. long offset = dataFile.storeData(data); id = idFile.storeOffset(offset); hashFile.storeID(getDataHash(data), id); } return id; }
/** * Stores the supplied value and returns the ID that has been assigned to it. In case the data to store is * already present, the ID of this existing data is returned. * * @param data * The data to store, must not be <tt>null</tt>. * @return The ID that has been assigned to the value. * @exception IOException * If an I/O error occurred. */ public int storeData(byte[] data) throws IOException { assert data != null : "data must not be null"; int id = getID(data); if (id == -1) { // Data not stored yet, store it under a new ID. long offset = dataFile.storeData(data); id = idFile.storeOffset(offset); hashFile.storeID(getDataHash(data), id); } return id; }