Update of /cvsroot/openantivirus/java/src/org/openantivirus/engine/vfs/entry
In directory sc8-pr-cvs1:/tmp/cvs-serv4777/java/src/org/openantivirus/engine/vfs/entry
Added Files:
TemporaryIsVfsEntry.java TemporaryVfsEntry.java
TemporaryOsVfsEntry.java FileVfsEntry.java
Log Message:
Rewrite of the engine to use a virtual file system
Move to 'engine' subdirectory
Added bzip2 and tar decompressors
Switch from GPL to MPL
--- NEW FILE: TemporaryIsVfsEntry.java ---
/*
* $Id: TemporaryIsVfsEntry.java,v 1.1 2003/12/14 11:08:26 kurti Exp $
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is OAV.
*
* The Initial Developer of the Original Code is Kurt Huwig <[email protected]>.
* Portions created by the Initial Developer are Copyright (C) 2001-2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** */
package org.openantivirus.engine.vfs.entry;
import java.io.*;
import org.openantivirus.engine.*;
/**
* Creates a temporary file from an InputStream that is deleted on 'dispose'
*
* Pattern-Roles:
* @author Kurt Huwig <[email protected]>
* @version $Revision: 1.1 $
*/
public class TemporaryIsVfsEntry extends TemporaryVfsEntry {
private static final int BUFFER_SIZE = 32768;
private final byte[] start;
private final InputStream is;
private boolean fileComplete;
public TemporaryIsVfsEntry(String name,
ScanConfiguration scanConf,
InputStream is) throws IOException {
super(name, scanConf);
this.is = is;
// read the start of the stream
int pos = 0;
byte[] buffer = new byte[MAX_START_SIZE];
int read;
while ((read = is.read(buffer, pos, MAX_START_SIZE - pos)) != -1) {
osTempFile.write(buffer, pos, read);
pos += read;
if (pos == MAX_START_SIZE) {
break;
}
}
fileComplete = (read == -1);
// if the file is smaller than the start-buffer, we have to
// create a smaller start-buffer and copy the file into it
if (pos < MAX_START_SIZE) {
start = new byte[pos];
System.arraycopy(buffer, 0, start, 0, pos);
} else {
start = buffer;
}
}
/**
* @return the first block of bytes from the object; buffer size is the
* minimum of file size and 4096
*/
public byte[] getStart() throws IOException {
return start;
}
public void dispose() throws IOException {
super.dispose();
is.close();
}
public File getFile() throws IOException {
if (!fileComplete) {
final byte[] buffer = new byte[MAX_START_SIZE];
// read the rest of the stream
int read;
while ((read = is.read(buffer)) != -1) {
osTempFile.write(buffer, 0, read);
}
is.close();
osTempFile.close();
fileComplete = true;
}
return super.getFile();
}
}
--- NEW FILE: TemporaryVfsEntry.java ---
/*
* $Id: TemporaryVfsEntry.java,v 1.1 2003/12/14 11:08:26 kurti Exp $
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is OAV.
*
* The Initial Developer of the Original Code is Kurt Huwig <[email protected]>.
* Portions created by the Initial Developer are Copyright (C) 2001-2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** */
package org.openantivirus.engine.vfs.entry;
import java.io.*;
import org.openantivirus.engine.*;
import org.openantivirus.engine.vfs.*;
/**
* Temporary entry that will be deleted
*
* Pattern-Roles:
* @author Kurt Huwig <[email protected]>
* @version $Revision: 1.1 $
*/
public abstract class TemporaryVfsEntry implements VfsEntry {
protected final OutputStream osTempFile;
protected final TemporaryFile tempFile;
protected final String name;
protected final ScanConfiguration scanConf;
public TemporaryVfsEntry(String name,
ScanConfiguration scanConf) throws IOException {
this.name = name;
this.scanConf = scanConf;
tempFile = new TemporaryFile(scanConf);
osTempFile = new FileOutputStream(tempFile.getFile());
}
/** called if the VfsEntry is not needed any more */
public void dispose() throws IOException {
osTempFile.close();
tempFile.delete();
}
/** @return File this entry represents; if */
public File getFile() throws IOException {
return tempFile.getFile();
}
public String getName() {
return name;
}
}
--- NEW FILE: TemporaryOsVfsEntry.java ---
/*
* $Id: TemporaryOsVfsEntry.java,v 1.1 2003/12/14 11:08:26 kurti Exp $
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is OAV.
*
* The Initial Developer of the Original Code is Kurt Huwig <[email protected]>.
* Portions created by the Initial Developer are Copyright (C) 2001-2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** */
package org.openantivirus.engine.vfs.entry;
import java.io.*;
import org.openantivirus.engine.*;
/**
* Temporary entry from an OutputStream
*
* Pattern-Roles:
* @author Kurt Huwig <[email protected]>
* @version $Revision: 1.1 $
*/
public class TemporaryOsVfsEntry extends TemporaryVfsEntry {
private final FileVfsEntry fileEntry;
public TemporaryOsVfsEntry(String name, ScanConfiguration scanConf)
throws IOException {
super(name, scanConf);
fileEntry = new FileVfsEntry(tempFile.getFile());
}
public OutputStream getOutputStream() {
return osTempFile;
}
public byte[] getStart() throws IOException {
return fileEntry.getStart();
}
}
--- NEW FILE: FileVfsEntry.java ---
/*
* $Id: FileVfsEntry.java,v 1.1 2003/12/14 11:08:26 kurti Exp $
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is OAV.
*
* The Initial Developer of the Original Code is Kurt Huwig <[email protected]>.
* Portions created by the Initial Developer are Copyright (C) 2001-2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** */
package org.openantivirus.engine.vfs.entry;
import java.io.*;
import org.openantivirus.engine.vfs.*;
/**
* Entry for a file
*
* Pattern-Roles:
* @author Kurt Huwig <[email protected]>
* @version $Revision: 1.1 $
*/
public class FileVfsEntry implements VfsEntry {
/** lazy initialized array with the start of the file */
private byte[] start = null;
/** file this entry represents */
private final File file;
private final String name;
public FileVfsEntry(File file) throws IOException {
this.file = file;
name = getRelativeName(file);
}
public FileVfsEntry(File file, String name) throws IOException {
this.file = file;
this.name = name;
}
public void dispose() throws IOException {
start = null;
}
/** @return (file-)name of the entry */
public String getName() {
return name;
}
/** @return File this entry represents */
public File getFile() {
return file;
}
/**
* @return the first block of bytes from the object; buffer size is the
* minimum of file size and 4096
*/
public byte[] getStart() throws IOException {
if (start == null) {
final RandomAccessFile raf = new RandomAccessFile(file, "r");
start = new byte[Math.min(MAX_START_SIZE, (int) file.length())];
raf.readFully(start);
raf.close();
}
return start;
}
public static String getRelativeName(File file) {
final String parent = file.getParent();
if (parent != null) {
return parent + File.separatorChar + file.getName();
} else {
return file.getName();
}
}
}
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.