Skip to content

Commit

Permalink
Bug 19105 - reuse the SimpleDateFormat instance
Browse files Browse the repository at this point in the history
  • Loading branch information
kahatlen authored and trondn committed Jan 2, 2013
1 parent 7a2e6a2 commit 995fff5
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/org/opensolaris/opengrok/web/DirectoryListing.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
Expand Down Expand Up @@ -60,15 +59,16 @@ public DirectoryListing(EftarFileReader desc) {
*
* @param out write destination
* @param child the file or directory to use for writing the data
* @param dateFormatter the formatter to use for pretty printing dates
*
* @throws NullPointerException if a parameter is {@code null}
*/
private void PrintDateSize(Writer out, File child) throws IOException {
Format dateFormatter = new SimpleDateFormat("dd-MMM-yyyy", Locale.getDefault());
Date lastm = new Date(child.lastModified());
private void PrintDateSize(Writer out, File child, Format dateFormatter)
throws IOException {
long lastm = child.lastModified();

out.write("<td>");
if (now - lastm.getTime() < 86400000) {
if (now - lastm < 86400000) {
out.write("Today");
} else {
out.write(dateFormatter.format(lastm));
Expand Down Expand Up @@ -98,7 +98,6 @@ private void PrintDateSize(Writer out, File child) throws IOException {
*/
public List<String> listTo(File dir, Writer out, String path, List<String> files) throws IOException {
// TODO this belongs to a jsp, not here
boolean dotdot = false;
ArrayList<String> readMes = new ArrayList<String>();
int offset = -1;
EftarFileReader.FNode parentFNode = null;
Expand All @@ -117,12 +116,13 @@ public List<String> listTo(File dir, Writer out, String path, List<String> files
out.write("</tr>\n</thead>\n<tbody>\n");
IgnoredNames ignoredNames = RuntimeEnvironment.getInstance().getIgnoredNames();

Format dateFormatter = new SimpleDateFormat("dd-MMM-yyyy", Locale.getDefault());

// print the '..' entry even for empty directories
if (!dotdot && path.length() != 0) {
if (path.length() != 0) {
out.write("<tr><td><p class=\"'r'\"/></td><td>");
dotdot = true;
out.write("<b><a href=\"..\">..</a></b></td>");
PrintDateSize(out, dir.getParentFile());
PrintDateSize(out, dir.getParentFile(), dateFormatter);
out.write("</tr>\n");
}

Expand Down Expand Up @@ -152,7 +152,7 @@ public List<String> listTo(File dir, Writer out, String path, List<String> files
out.write("</a>");
}
out.write("</td>");
PrintDateSize(out, child);
PrintDateSize(out, child, dateFormatter);
if (offset > 0) {
String briefDesc = desc.getChildTag(parentFNode, file);
if (briefDesc == null) {
Expand Down

0 comments on commit 995fff5

Please sign in to comment.