WindowsDirectoryListingFormatter.java revision 2a0a3f946dba517a01cc26278f905156857c9c91
1/* 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; 22 23/** 24 * Windows-specific implementation of the DirectoryListingFormatter interface. 25 * 26 * @author Chris Mair 27 * @version $Revision$ - $Date$ 28 */ 29public class WindowsDirectoryListingFormatter implements DirectoryListingFormatter { 30 31 private static final String DATE_FORMAT = "MM-dd-yy hh:mmaa"; 32 private static final int SIZE_WIDTH = 15; 33 34 /** 35 * Format the directory listing for a single file/directory entry. 36 * 37 * @param fileSystemEntry - the FileSystemEntry for a single file system entry 38 * @return the formatted directory listing 39 */ 40 public String format(FileSystemEntry fileSystemEntry) { 41 DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); 42 String dateStr = dateFormat.format(fileSystemEntry.getLastModified()); 43 String dirOrSize = fileSystemEntry.isDirectory() 44 ? StringUtil.padRight("<DIR>", SIZE_WIDTH) 45 : StringUtil.padLeft(Long.toString(fileSystemEntry.getSize()), SIZE_WIDTH); 46 return dateStr + " " + dirOrSize + " " + fileSystemEntry.getName(); 47 } 48 49}