|
|
Исходный текст программы CheckCheckSum.java
|
Оглавление |
Назад
// ==========================================
// CheckCheckSum.java
//(C) Alexandr Frolov, 1998
// E-mail: frolov@glasnet.ru
// Web: http://www.glasnet.ru/~frolov
// ==========================================
import java.applet.*;
import java.awt.*;
import java.net.*;
import java.io.*;
import java.util.zip.*;
public class CheckCheckSum extends Applet
{
URL u;
String szChecksum = null;
Checksum cs = new CRC32();
// ============================================
// init
// ============================================
public void init()
{
try
{
u = getCodeBase();
u = new URL(u.toString() +
"CheckCheckSum.class");
InputStream is = u.openStream();
CheckedInputStream cis =
new CheckedInputStream(is, cs);
szChecksum = calculate(cis);
}
catch(Exception ioe)
{
showStatus(ioe.toString());
}
setBackground(Color.yellow);
}
// ============================================
// calculate
// ============================================
String calculate(CheckedInputStream is)
{
byte[] buf = new byte[8000];
int nLength = 0;
try
{
while(true)
{
int nReaded = is.read(buf);
if(nReaded == -1)
break;
}
is.close();
}
catch(Exception ioe)
{
showStatus(ioe.toString());
}
String s = (new Long(
is.getChecksum().getValue())).toString();
return s;
}
// ============================================
// paint
// ============================================
public void paint(Graphics g)
{
g.drawString("My own URL: " + u.toString(),
10, 30);
g.drawString("My own CRC-32: " + szChecksum,
10, 50);
}
}
|
|
|