Coverage Report - org.mockftpserver.fake.filesystem.WindowsDirectoryListingFormatter
 
Classes in this File Line Coverage Branch Coverage Complexity
WindowsDirectoryListingFormatter
100%
5/5
100%
2/2
2
 
 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  
  */
 16  
 package org.mockftpserver.fake.filesystem;
 17  
 
 18  
 import org.mockftpserver.core.util.StringUtil;
 19  
 
 20  
 import java.text.DateFormat;
 21  
 import java.text.SimpleDateFormat;
 22  
 import java.util.Locale;
 23  
 
 24  
 /**
 25  
  * Windows-specific implementation of the DirectoryListingFormatter interface.
 26  
  *
 27  
  * @author Chris Mair
 28  
  * @version $Revision: 225 $ - $Date: 2009-03-09 21:15:24 -0400 (Mon, 09 Mar 2009) $
 29  
  */
 30  87
 public 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  7
         DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH);
 43  7
         String dateStr = dateFormat.format(fileSystemEntry.getLastModified());
 44  7
         String dirOrSize = fileSystemEntry.isDirectory()
 45  
                 ? StringUtil.padRight("<DIR>", SIZE_WIDTH)
 46  
                 : StringUtil.padLeft(Long.toString(fileSystemEntry.getSize()), SIZE_WIDTH);
 47  7
         return dateStr + "  " + dirOrSize + "  " + fileSystemEntry.getName();
 48  
     }
 49  
 
 50  
 }