
com.sta.cts.ProgressInputStream Maven / Gradle / Ivy
package com.sta.cts;
import java.io.InputStream;
import java.io.IOException;
import java.io.FilterInputStream;
/**
* Name: ProgressInputStream
* Description: Input-Stream mit Fortschrittsermittlung.
* Copyright: Copyright (c) 2004, 2009, 2016, 2017, 2019, 2021
* Company: >StA-Soft<
* @author StA
* @version 1.0
*/
public class ProgressInputStream extends FilterInputStream
{
/**
* Dateigr??e.
*/
private long myFileSize;
/**
* Aktuelle Position in der Datei.
*/
private long myFilePos;
//===========================================================================
/**
* Constructor mit InputStream.
* @param in zu verwendender InputStream
*/
public ProgressInputStream(InputStream in)
{
super(in);
myFileSize = 0;
myFilePos = 0;
try
{
myFileSize = in.available();
}
catch (IOException ioe)
{
}
}
//===========================================================================
@Override
public int read() throws IOException
{
int i = in.read();
if (i >= 0)
{
myFilePos++;
}
return i;
}
@Override
public int read(byte[] b) throws IOException
{
int cnt = in.read(b);
if (cnt > 0)
{
myFilePos += cnt;
}
return cnt;
}
@Override
public int read(byte[] b, int off, int len) throws IOException
{
int cnt = in.read(b, off, len);
if (cnt > 0)
{
myFilePos += cnt;
}
return cnt;
}
@Override
public long skip(long n) throws IOException
{
long cnt = in.skip(n);
if (cnt > 0)
{
myFilePos += cnt;
}
return cnt;
}
@Override
public void close() throws IOException
{
in.close();
}
@Override
public /* synchronized */ void reset() throws IOException
{
in.reset();
myFilePos = myFileSize - in.available();
}
/**
* Dateigr??e ermitteln.
* @return Dateigr??e
*/
public long getFileSize()
{
return myFileSize;
}
/**
* Position in der Datei ermitteln.
* @return Position in der Datei
*/
public long getFilePos()
{
return myFilePos;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy