1 /***
2 *
3 */
4 package com.fernsroth.squashfs;
5
6 import com.fernsroth.squashfs.model.BaseFile;
7 import com.fernsroth.squashfs.model.Directory;
8 import com.fernsroth.squashfs.model.SymLink;
9
10 /***
11 *
12 * @author Joseph M. Ferner (Near Infinity Corporation)
13 */
14 public class LSWalkHandler implements WalkHandler {
15
16 /***
17 * {@inheritDoc}
18 */
19 public void visit(Directory[] path, BaseFile bf) {
20 String line = SquashFSUtils.getModeString(bf);
21
22 line += String.format(" %5d %5d ", new Object[] { bf.getUid(),
23 bf.getGuid() });
24
25 line += SquashFSUtils.LINUX_DATE_FORMAT.format(SquashFSUtils
26 .getDateFromMTime(bf.getMTime()));
27
28 line += " ";
29 line += printPath(path);
30 line += bf.getName() == null ? "" : bf.getName();
31 line += bf instanceof Directory ? "/" : "";
32 if (bf instanceof SymLink) {
33 line += " -> " + ((SymLink) bf).getLinkName();
34 }
35 System.out.println(line);
36 }
37
38 /***
39 * prints the path to the string.
40 * @param path the path to print.
41 * @return the string.
42 */
43 private String printPath(Directory[] path) {
44 StringBuffer result = new StringBuffer();
45 for (Directory dir : path) {
46 if (dir.getName() != null) {
47 result.append(dir.getName());
48 result.append('/');
49 }
50 }
51 return result.toString();
52 }
53
54 }