Permalink
Browse files

Merge pull request #18 from andrewgaul/closeable

Use standard Closeable instead of custom Closable
  • Loading branch information...
chirino committed May 25, 2012
2 parents 0467761 + cdbd442 commit 1715f962d07485c18eab6bfd1bcfe78682b3b3b5
@@ -1,27 +0,0 @@
-/**
- * Copyright (C) 2011 the original author or authors.
- * See the notice.md file distributed with this work for additional
- * information regarding copyright ownership.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.iq80.leveldb;
-
-/**
- * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
- */
-public interface Closable {
-
- public void close();
-
-}
@@ -17,12 +17,13 @@
*/
package org.iq80.leveldb;
+import java.io.Closeable;
import java.util.Map;
/**
* @author <a href="http://hiramchirino.com">Hiram Chirino</a>
*/
-public interface DB extends Iterable<Map.Entry<byte[], byte[]>>, Closable {
+public interface DB extends Iterable<Map.Entry<byte[], byte[]>>, Closeable {
public byte[] get(byte[] key) throws DBException;
public byte[] get(byte[] key, ReadOptions options) throws DBException;
@@ -17,13 +17,14 @@
*/
package org.iq80.leveldb;
+import java.io.Closeable;
import java.util.Iterator;
import java.util.Map;
/**
* @author <a href="http://hiramchirino.com">Hiram Chirino</a>
*/
-public interface DBIterator extends Iterator<Map.Entry<byte[], byte[]>>, Closable {
+public interface DBIterator extends Iterator<Map.Entry<byte[], byte[]>>, Closeable {
/**
* Repositions the iterator so the key of the next BlockElement
@@ -17,6 +17,8 @@
*/
package org.iq80.leveldb;
-public interface Snapshot extends Closable {
+import java.io.Closeable;
+
+public interface Snapshot extends Closeable {
}
@@ -17,10 +17,12 @@
*/
package org.iq80.leveldb;
+import java.io.Closeable;
+
/**
* @author <a href="http://hiramchirino.com">Hiram Chirino</a>
*/
-public interface WriteBatch extends Closable {
+public interface WriteBatch extends Closeable {
public WriteBatch put(byte[] key, byte[] value);
public WriteBatch delete(byte[] key);
@@ -22,6 +22,7 @@
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.io.CharStreams;
+import com.google.common.io.Closeables;
import com.google.common.io.Files;
import org.iq80.leveldb.impl.DbImpl;
import org.iq80.leveldb.util.*;
@@ -440,7 +441,7 @@ private void readSequential()
bytes_ += entry.getKey().length + entry.getValue().length;
finishedSingleOp();
}
- iterator.close();
+ Closeables.closeQuietly(iterator);
}
}
@@ -603,10 +604,8 @@ private void heapProfile()
private void destroyDb()
{
- if (db_ != null) {
- db_.close();
- db_ = null;
- }
+ Closeables.closeQuietly(db_);
+ db_ = null;
FileUtils.deleteRecursively(databaseDir);
}

0 comments on commit 1715f96

Please sign in to comment.