blob: 9479e64195802f639079674be21f455a167139bf [file] [log] [blame]
chrismair00dc7bd2014-05-11 21:21:28 +00001/*
2 * Copyright 2008 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.mockftpserver.fake.filesystem;
17
18import org.mockftpserver.core.util.StringUtil;
19
20import java.text.DateFormat;
21import java.text.SimpleDateFormat;
22import java.util.Locale;
23
24/**
25 * Windows-specific implementation of the DirectoryListingFormatter interface.
26 *
27 * @author Chris Mair
28 * @version $Revision$ - $Date$
29 */
30public class WindowsDirectoryListingFormatter implements DirectoryListingFormatter {
31
32 private static final String DATE_FORMAT = "MM-dd-yy hh:mmaa";
33 private static final int SIZE_WIDTH = 15;
34
35 /**
36 * Format the directory listing for a single file/directory entry.
37 *
38 * @param fileSystemEntry - the FileSystemEntry for a single file system entry
39 * @return the formatted directory listing
40 */
41 public String format(FileSystemEntry fileSystemEntry) {
42 DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH);
43 String dateStr = dateFormat.format(fileSystemEntry.getLastModified());
44 String dirOrSize = fileSystemEntry.isDirectory()
45 ? StringUtil.padRight("<DIR>", SIZE_WIDTH)
46 : StringUtil.padLeft(Long.toString(fileSystemEntry.getSize()), SIZE_WIDTH);
47 return dateStr + " " + dirOrSize + " " + fileSystemEntry.getName();
48 }
49
50}