");
126 | }
127 | else {
128 | sb.append("class=\"oddrow\">");
129 | }
130 | sb.append("");
131 | sb.append("");
134 | if (content.isDirectory()) {
135 | sb.append(" ");
136 | }
137 | else {
138 | sb.append(" ");
139 | }
140 | if (nameOverride != null) {
141 | sb.append(nameOverride);
142 | }
143 | else {
144 | sb.append(content.getName());
145 | }
146 | sb.append("");
147 | sb.append(" | ");
148 | sb.append("");
149 | if (content.isDirectory()) {
150 | sb.append("-");
151 | }
152 | else {
153 | sb.append(humanReadableByteCount(content.length(), true));
154 | }
155 | sb.append(" | ");
156 | sb.append("");
157 | sb.append(timeFormat.format(content.lastModified()));
158 | sb.append(" | ");
159 | sb.append("
");
160 | }
161 | return sb.toString();
162 | }
163 |
164 | private String getKey(String target) {
165 | try {
166 | return target.split("/")[1];
167 | }
168 | catch (Exception e) {
169 | }
170 | return "";
171 | }
172 |
173 | private void penalize() {
174 | try {
175 | Thread.sleep(1000);
176 | }
177 | catch (InterruptedException e) {
178 | e.printStackTrace();
179 | }
180 | }
181 |
182 | /**
183 | * Turn a raw filesize into a human readable one
184 | *
185 | * @param bytes
186 | * raw size
187 | * @param si
188 | * use SI units
189 | * @return formated string.
190 | */
191 | public static String humanReadableByteCount(long bytes, boolean si) {
192 | int unit = si ? 1000 : 1024;
193 | if (bytes < unit)
194 | return bytes + " B";
195 | int exp = (int) (Math.log(bytes) / Math.log(unit));
196 | String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");
197 | return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
198 | }
199 |
200 | }
201 |
--------------------------------------------------------------------------------
/src/main/java/de/onyxbits/filecast/io/Store.java:
--------------------------------------------------------------------------------
1 | package de.onyxbits.filecast.io;
2 |
3 | import java.io.File;
4 | import java.util.HashMap;
5 | import java.util.Random;
6 |
7 | import org.eclipse.jetty.util.log.Log;
8 | import org.eclipse.jetty.util.log.Logger;
9 |
10 | /**
11 | * Central registry for keeping track (and providing access control) for what
12 | * files are shared over the network.
13 | *
14 | * @author patrick
15 | *
16 | */
17 | public class Store {
18 |
19 | private HashMap