📄 archiveloader.java
字号:
/*
* $Log: ArchiveLoader.java,v $
* Revision 1.2 2003/02/25 17:18:52 willaxt
* updated javadoc comments
* prevented storing incomplete loaded byte array in loadArchive
* no if the archive is loaded incompletely due to an exception,
* the byte array is reset to null
*
* Revision 1.1 2003/02/12 16:42:52 mwulff
* initial version
*
*/
package de.fhm.jkf.launch.cl;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.swing.ProgressMonitorInputStream;
/**
* <br><br><center><table border="1" width="80%"><hr>
* <strong><a href="http://jkf.sourceforge.net">The JKF Project</a></strong>
* <p>
* Copyright (C) 2002 by Marten Wulff
* <p>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* <p>
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* <p>
* You should have received a copy of the <a href="http://www.gnu.org/copyleft/lesser.html">
* GNU Lesser General Public License</a> along with this library; if not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
* <hr></table></center>
*
* Responsible for displaying a progress bar, if an archive is
* loaded over the net.
*
* @author marten wulff
* @version 1.0
*/
public class ArchiveLoader {
/** the InputStream from which should be read data. */
private InputStream in = null;
/** stores the date read from the InputStream. */
private byte[] data = null;
/** Max data length. */
private long max = -1;
/** Name of the archive to load. */
private String archiveName = "Unknown";
/**
* Constructs an object which monitors loading of
* an java archive.
*
* @param in The input stream to read from.
*/
public ArchiveLoader(InputStream in, long max, String archiveName) {
this.in = in;
this.max = max;
this.archiveName = archiveName;
}
/**
* Does the loading of the archive and displays a
* progress bar according the load progress.
*/
public void loadArchive() {
ProgressMonitorInputStream pmis =
new ProgressMonitorInputStream(null, "Reading archive " + archiveName, in);
pmis.getProgressMonitor().setMillisToDecideToPopup(1);
pmis.getProgressMonitor().setMillisToPopup(1);
pmis.getProgressMonitor().setMaximum((int) max);
InputStream buffIn = new BufferedInputStream(pmis);
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
int len;
byte[] buf = new byte[4096];
while ((len = buffIn.read(buf)) > 0) {
out.write(buf, 0, len);
}
buffIn.close();
data = out.toByteArray();
out.close();
} catch (IOException e) {
e.printStackTrace();
// don't return incomplete archive
data = null;
}
}
/**
* Returns the <code>byte</code>s that repressent
* the loaded archive. It is mandatory that
* <code>loadArchive</code> is called before you
* call this method.
*
* @return The loaded archive or <code>null</code> if
* no archive was loaded.
*/
public byte[] getData() {
return data;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -