System.out.println("Server: Opening file \""+filename+'"');
FileInputStream fileIn = new FileInputStream(filename);
// wrap stream
if (fVerbose) System.out.println("Server: Wrapping output stream.");
WrappedOutputStream wrappedOut = new WrappedOutputStream(clientStream);
// read file, writing to output
int total = 0;
while (true) {
// read random amount
//int length = (Math.abs(random.nextInt()) % fBuffer.length) + 1;
int length = fBuffer.length;
if (fVerbose) System.out.println("Server: Attempting to read "+length+" byte(s).");
int count = fileIn.read(fBuffer, 0, length);
if (count == -1) {
if (fVerbose) System.out.println("Server: EOF.");
break;
}
if (fVerbose) System.out.println("Server: Writing "+count+" byte(s) to wrapped output stream.");
wrappedOut.write(fBuffer, 0, count);
total += count;
}
System.out.println("Server: Wrote "+total+" byte(s) total.");
// close stream
if (fVerbose) System.out.println("Server: Closing output stream.");
wrappedOut.close();
// close file
if (fVerbose) System.out.println("Server: Closing file.");
fileIn.close();
}