You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by tr...@apache.org on 2005/06/06 13:09:09 UTC
svn commit: r180292 - in
/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core:
fs/local/HandleMonitor.java fs/local/LocalFileSystem.java
util/LazyFileInputStream.java value/InternalValue.java
Author: tripod
Date: Mon Jun 6 04:09:08 2005
New Revision: 180292
URL: http://svn.apache.org/viewcvs?rev=180292&view=rev
Log:
[JCR-128] Deleting binary property does not remove 'blob file' in filesystem
Added:
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/util/LazyFileInputStream.java (with props)
Modified:
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/fs/local/HandleMonitor.java
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/fs/local/LocalFileSystem.java
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/value/InternalValue.java
Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/fs/local/HandleMonitor.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/fs/local/HandleMonitor.java?rev=180292&r1=180291&r2=180292&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/fs/local/HandleMonitor.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/fs/local/HandleMonitor.java Mon Jun 6 04:09:08 2005
@@ -17,6 +17,7 @@
package org.apache.jackrabbit.core.fs.local;
import org.apache.log4j.Logger;
+import org.apache.jackrabbit.core.util.LazyFileInputStream;
import java.util.HashMap;
import java.util.Iterator;
@@ -24,8 +25,7 @@
import java.io.InputStream;
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.FileInputStream;
-import java.io.IOException;
+import java.io.FileDescriptor;
/**
* This Class implements a very simple open handle monitor for the local
@@ -185,12 +185,7 @@
* Delegating input stream that registers/unregisters itself from the
* handle.
*/
- private class MonitoredInputStream extends InputStream {
-
- /**
- * the underlying input stream
- */
- private final FileInputStream in;
+ private class MonitoredInputStream extends LazyFileInputStream {
/**
* throwable of the time, the stream was created
@@ -198,12 +193,11 @@
private final Throwable throwable;
/**
- * Creates a new stream
- * @param file
- * @throws FileNotFoundException
+ * {@inheritDoc}
*/
public MonitoredInputStream(File file) throws FileNotFoundException {
- in = new FileInputStream(file);
+ super(file);
+ // register the throwable
try {
throw new Exception();
} catch (Exception e) {
@@ -212,75 +206,38 @@
}
/**
- * dumps this stream
- */
- public void dump() {
- log.info("- opened by : ", throwable);
- }
-
- /**
- * {@inheritDoc}
- */
- public int available() throws IOException {
- return in.available();
- }
-
- /**
- * {@inheritDoc}
- */
- public void close() throws IOException {
- in.close();
- Handle.this.close(this);
- }
-
- /**
- * {@inheritDoc}
- */
- public synchronized void reset() throws IOException {
- in.reset();
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean markSupported() {
- return in.markSupported();
- }
-
- /**
- * {@inheritDoc}
- */
- public synchronized void mark(int readlimit) {
- in.mark(readlimit);
- }
-
- /**
* {@inheritDoc}
*/
- public long skip(long n) throws IOException {
- return in.skip(n);
+ public MonitoredInputStream(FileDescriptor fdObj) {
+ super(fdObj);
+ // register the throwable
+ try {
+ throw new Exception();
+ } catch (Exception e) {
+ throwable = e;
+ }
}
/**
* {@inheritDoc}
*/
- public int read(byte b[]) throws IOException {
- return in.read(b);
+ public MonitoredInputStream(String name) throws FileNotFoundException {
+ super(name);
+ // register the throwable
+ try {
+ throw new Exception();
+ } catch (Exception e) {
+ throwable = e;
+ }
}
/**
- * {@inheritDoc}
+ * dumps this stream
*/
- public int read(byte b[], int off, int len) throws IOException {
- return in.read(b, off, len);
+ public void dump() {
+ log.info("- opened by : ", throwable);
}
- /**
- * {@inheritDoc}
- */
- public int read() throws IOException {
- return in.read();
- }
}
}
Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/fs/local/LocalFileSystem.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/fs/local/LocalFileSystem.java?rev=180292&r1=180291&r2=180292&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/fs/local/LocalFileSystem.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/fs/local/LocalFileSystem.java Mon Jun 6 04:09:08 2005
@@ -19,6 +19,7 @@
import org.apache.jackrabbit.core.fs.FileSystem;
import org.apache.jackrabbit.core.fs.FileSystemException;
import org.apache.jackrabbit.core.fs.RandomAccessOutputStream;
+import org.apache.jackrabbit.core.util.LazyFileInputStream;
import org.apache.log4j.Logger;
import java.io.File;
@@ -230,7 +231,7 @@
File f = new File(root, osPath(filePath));
try {
if (monitor == null) {
- return new FileInputStream(f);
+ return new LazyFileInputStream(f);
} else {
return monitor.open(f);
}
Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/util/LazyFileInputStream.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/util/LazyFileInputStream.java?rev=180292&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/util/LazyFileInputStream.java (added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/util/LazyFileInputStream.java Mon Jun 6 04:09:08 2005
@@ -0,0 +1,184 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * 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.apache.jackrabbit.core.util;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.FileDescriptor;
+import java.io.File;
+import java.io.FileNotFoundException;
+
+/**
+ * This Class implements an InputStream that provides the same functionality
+ * as a <code>FileInputStream</code> but opens the file by the first file access.
+ */
+public class LazyFileInputStream extends InputStream {
+
+ /**
+ * the underlying input stream
+ */
+ private FileInputStream in;
+
+ /**
+ * FileDescriptor to use
+ */
+ private FileDescriptor fd;
+
+ /**
+ * File to use
+ */
+ private File file;
+
+ /**
+ * Creates a new <code>LazyFileInputStream</code> for the given file. If the
+ * file is unreadably, a FileNotFoundException is thrown.
+ *
+ * @param file
+ * @throws FileNotFoundException
+ */
+ public LazyFileInputStream(File file)
+ throws FileNotFoundException {
+ // check if we can read from the file
+ if (!file.canRead()) {
+ throw new FileNotFoundException(file.getPath());
+ }
+ this.file = file;
+ }
+
+ /**
+ * Creates a new <code>LazyFileInputStream</code> for the given file
+ * desciptor.
+ *
+ * @param fdObj
+ */
+ public LazyFileInputStream(FileDescriptor fdObj) {
+ this.fd = fdObj;
+ }
+
+ /**
+ * Creates a new <code>LazyFileInputStream</code> for the given file. If the
+ * file is unreadably, a FileNotFoundException is thrown.
+ *
+ * @param name
+ * @throws FileNotFoundException
+ */
+ public LazyFileInputStream(String name) throws FileNotFoundException {
+ this(new File(name));
+ }
+
+ /**
+ * Opens the underlying file input stream in neccessairy.
+ * @throws IOException
+ */
+ public void open() throws IOException {
+ if (in == null) {
+ if (file != null) {
+ in = new FileInputStream(file);
+ } else if (fd != null) {
+ in = new FileInputStream(fd);
+ } else {
+ throw new IOException("Stream already closed.");
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int read() throws IOException {
+ open();
+ return in.read();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int available() throws IOException {
+ open();
+ return in.available();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void close() throws IOException {
+ if (in != null) {
+ in.close();
+ }
+ in = null;
+ file = null;
+ fd = null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public synchronized void reset() throws IOException {
+ open();
+ in.reset();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean markSupported() {
+ try {
+ open();
+ return in.markSupported();
+ } catch (IOException e) {
+ throw new IllegalStateException(e.toString());
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public synchronized void mark(int readlimit) {
+ try {
+ open();
+ in.mark(readlimit);
+ } catch (IOException e) {
+ throw new IllegalStateException(e.toString());
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long skip(long n) throws IOException {
+ open();
+ return in.skip(n);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int read(byte[] b) throws IOException {
+ open();
+ return in.read(b);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int read(byte[] b, int off, int len) throws IOException {
+ open();
+ return in.read(b, off, len);
+ }
+
+}
Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/util/LazyFileInputStream.java
------------------------------------------------------------------------------
svn =
Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/util/LazyFileInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/value/InternalValue.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/value/InternalValue.java?rev=180292&r1=180291&r2=180292&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/value/InternalValue.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/value/InternalValue.java Mon Jun 6 04:09:08 2005
@@ -299,7 +299,7 @@
throws RepositoryException {
switch (type) {
case PropertyType.BINARY:
- return (BLOBFileValue) val;
+ return new BinaryValue(((BLOBFileValue) val).getStream());
case PropertyType.BOOLEAN:
return new BooleanValue(((Boolean) val));
case PropertyType.DATE: