P
phillip.s.powell
My Java-based chatroom is failing to do its automatic CRON job to
delete latent messages and nicknames that linger on the server more
than an hour.
I set up a few JSP scripts that will retrieve and remove these files by
comparing the last modified date of messages.txt to determine if the
very last message left is more than an hour old; if so, delete it.
As of 1/1/2005, this process no longer works and I am baffled as to why
this is happening; I am getting comparison integer values from "then"
to "now" of 1 microsecond every time, no matter how far apart the dates
of "now" and "then".
Meanwhile, in the attempt to debug this problem I am getting nasty
compiler errors.
What I'm doing very simply is to try to get the last modified date of a
file, period.
Here is the code:
try {
File file = new File(request.getParameter("fileName"));
Long blah = file.lastModified();
Date sometime = new Date(blah);
out.print("last modified: " + sometime + "\n\n<P><P>");
} catch (Exception e) {
e.printStackTrace();
}
Here is the error:
Note: sun.tools.javac.Main has been deprecated.
/~ppowell/includes/file_retrieval.jsp:11: Incompatible type for
declaration.
Can't convert long to java.lang.Long.
java.lang.Long blah = file.lastModified();
^
/~ppowell/includes/file_retrieval.jsp:12: Incompatible type for
constructor.
Can't convert java.lang.Long to java.lang.String.
Date sometime = new Date(blah);
^
2 errors, 1 warning
I was under the impression that file.lastModified() returns a Long.
Can someone debug this very simple problem for me and tell me what I
did wrong? That way I can make a bit more progress in the attempt to
debug this:
package ppowell;
import java.io.*;
import java.util.Vector;
/**
* Retrieves flat files for parse/usage
*
* @version JDK 1.4
* @author Phil Powell
* @package PPOWELL
*/
public class FlatFileRetriever implements Retriever {
private String fileName = "";
/**
* Constructor
*
* @access public
* @param String fileName
*/
public FlatFileRetriever(String fileName) {
this.fileName = fileName;
}
//------------------- --* GETTER/SETTER METHODS *--
---------------------
/**
* Must contain this method as it implements Retriever but leave blank
to be
* overriden later
*
* @access public
* @return String
*/
public String getCookieVal() { // STRING METHOD
return "";
}
/**
* Retrieve file contents if dynamic via synchronized block
*
* @access public
* @return Vector contentVector
*/
public synchronized Vector getDynamicFileContents() { // VECTOR METHOD
Vector contentVector = getFileContents();
return contentVector;
}
/**
* Retrieve file contents into Vector
*
* @access public
* @return Vector contentVector
*/
public Vector getFileContents() { // VECTOR METHOD
Vector contentVector = new Vector();
try {
BufferedReader in = new BufferedReader(new
FileReader(this.fileName));
String stuff = "";
while ((stuff = in.readLine()) != null) contentVector.add(stuff);
in.close();
} catch (Exception e) {
e.printStackTrace();
}
return contentVector;
}
/**
* Must contain this method as it implements Retriever interface but
leave blank to
* be overridden later
*
* @access public
* @return String HTML
*/
public String getHTML() { // STRING METHOD
return "";
}
/**
* Get last modified date of file referenced by string
*
* @access public
* @return long lastModified date
*/
public long getLastModified() { // LONG METHOD
File file = new File(this.fileName);
if (file.exists()) return file.lastModified();
return 0;
}
//------------------ --* END OF GETTER/SETTER METHODS *--
-------------------
/**
* Return boolean if file exists or not
*
* @access public
* @return boolean exists
*/
public boolean exists() { // BOOLEAN METHOD
File file = new File(this.fileName);
return file.exists();
}
}
Thanx
Phil
delete latent messages and nicknames that linger on the server more
than an hour.
I set up a few JSP scripts that will retrieve and remove these files by
comparing the last modified date of messages.txt to determine if the
very last message left is more than an hour old; if so, delete it.
As of 1/1/2005, this process no longer works and I am baffled as to why
this is happening; I am getting comparison integer values from "then"
to "now" of 1 microsecond every time, no matter how far apart the dates
of "now" and "then".
Meanwhile, in the attempt to debug this problem I am getting nasty
compiler errors.
What I'm doing very simply is to try to get the last modified date of a
file, period.
Here is the code:
try {
File file = new File(request.getParameter("fileName"));
Long blah = file.lastModified();
Date sometime = new Date(blah);
out.print("last modified: " + sometime + "\n\n<P><P>");
} catch (Exception e) {
e.printStackTrace();
}
Here is the error:
Note: sun.tools.javac.Main has been deprecated.
/~ppowell/includes/file_retrieval.jsp:11: Incompatible type for
declaration.
Can't convert long to java.lang.Long.
java.lang.Long blah = file.lastModified();
^
/~ppowell/includes/file_retrieval.jsp:12: Incompatible type for
constructor.
Can't convert java.lang.Long to java.lang.String.
Date sometime = new Date(blah);
^
2 errors, 1 warning
I was under the impression that file.lastModified() returns a Long.
Can someone debug this very simple problem for me and tell me what I
did wrong? That way I can make a bit more progress in the attempt to
debug this:
package ppowell;
import java.io.*;
import java.util.Vector;
/**
* Retrieves flat files for parse/usage
*
* @version JDK 1.4
* @author Phil Powell
* @package PPOWELL
*/
public class FlatFileRetriever implements Retriever {
private String fileName = "";
/**
* Constructor
*
* @access public
* @param String fileName
*/
public FlatFileRetriever(String fileName) {
this.fileName = fileName;
}
//------------------- --* GETTER/SETTER METHODS *--
---------------------
/**
* Must contain this method as it implements Retriever but leave blank
to be
* overriden later
*
* @access public
* @return String
*/
public String getCookieVal() { // STRING METHOD
return "";
}
/**
* Retrieve file contents if dynamic via synchronized block
*
* @access public
* @return Vector contentVector
*/
public synchronized Vector getDynamicFileContents() { // VECTOR METHOD
Vector contentVector = getFileContents();
return contentVector;
}
/**
* Retrieve file contents into Vector
*
* @access public
* @return Vector contentVector
*/
public Vector getFileContents() { // VECTOR METHOD
Vector contentVector = new Vector();
try {
BufferedReader in = new BufferedReader(new
FileReader(this.fileName));
String stuff = "";
while ((stuff = in.readLine()) != null) contentVector.add(stuff);
in.close();
} catch (Exception e) {
e.printStackTrace();
}
return contentVector;
}
/**
* Must contain this method as it implements Retriever interface but
leave blank to
* be overridden later
*
* @access public
* @return String HTML
*/
public String getHTML() { // STRING METHOD
return "";
}
/**
* Get last modified date of file referenced by string
*
* @access public
* @return long lastModified date
*/
public long getLastModified() { // LONG METHOD
File file = new File(this.fileName);
if (file.exists()) return file.lastModified();
return 0;
}
//------------------ --* END OF GETTER/SETTER METHODS *--
-------------------
/**
* Return boolean if file exists or not
*
* @access public
* @return boolean exists
*/
public boolean exists() { // BOOLEAN METHOD
File file = new File(this.fileName);
return file.exists();
}
}
Thanx
Phil