All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class Acme.Serve.ThrottledOutputStream

java.lang.Object
   |
   +----java.io.OutputStream
           |
           +----java.io.FilterOutputStream
                   |
                   +----Acme.Serve.ThrottledOutputStream

public class ThrottledOutputStream
extends FilterOutputStream
Output stream with throttling.

Restricts output to a specified rate. Also includes a static utility routine for parsing a file of throttle settings.

Fetch the software.
Fetch the entire Acme package.


Constructor Index

 o ThrottledOutputStream(OutputStream, long)
Constructor.

Method Index

 o parseThrottleFile(String)
Parses a standard throttle file.
 o write(byte[], int, int)
Writes a subarray of bytes.
 o write(int)
Writes a byte.

Constructors

 o ThrottledOutputStream
 public ThrottledOutputStream(OutputStream out,
                              long maxBps)
Constructor.

Methods

 o parseThrottleFile
 public static WildcardDictionary parseThrottleFile(String filename) throws IOException
Parses a standard throttle file.

A throttle file lets you set maximum byte rates on filename patterns. The format of the throttle file is very simple. A # starts a comment, and the rest of the line is ignored. Blank lines are ignored. The rest of the lines should consist of a pattern, whitespace, and a number. The pattern is a simple shell-style filename pattern, using ? and *, or multiple such patterns separated by |.

The numbers in the file are byte rates, specified in units of bytes per second. For comparison, a v.32b/v.42b modem gives about 1500/2000 B/s depending on compression, a double-B-channel ISDN line about 12800 B/s, and a T1 line is about 150000 B/s.

Example:

 # throttle file for www.acme.com
 *               100000  # limit total web usage to 2/3 of our T1
 *.jpg|*.gif     50000   # limit images to 1/3 of our T1
 *.mpg           20000   # and movies to even less
 jef/*           20000   # jef's pages are too popular
 

The routine returns a WildcardDictionary. Do a lookup in this dictionary using a filename, and you'll get back a ThrottleItem containing the corresponding byte rate.

 o write
 public void write(int b) throws IOException
Writes a byte. This method will block until the byte is actually written.

Parameters:
b - the byte to be written
Throws: IOException
if an I/O error has occurred
Overrides:
write in class FilterOutputStream
 o write
 public void write(byte b[],
                   int off,
                   int len) throws IOException
Writes a subarray of bytes.

Parameters:
b - the data to be written
off - the start offset in the data
len - the number of bytes that are written
Throws: IOException
if an I/O error has occurred
Overrides:
write in class FilterOutputStream

All Packages  Class Hierarchy  This Package  Previous  Next  Index

ACME Java  ACME Labs