/*
* Copyright (c) 1997-2024 IDRsolutions (https://www.idrsolutions.com)
*/
package org.jpedal.examples.handlers;
import org.jpedal.io.DefaultErrorTracker;
/**
* @author Bethan
* <p>
* example implementation
*/
@SuppressWarnings({"ClassOnlyUsedInOneModule", "ClassOnlyUsedInOnePackage"})
public class ExampleOutputErrorTracker extends DefaultErrorTracker {
private long timeAtStart;
private boolean userFailedPage;
@Override
public String getPageFailureMessage() {
if (userFailedPage) {
return "Timed out on page";
} else {
return super.getPageFailureMessage();
}
}
@Override
//use to see if page failed
public boolean ispageSuccessful() {
return !userFailedPage && super.ispageSuccessful();
}
@Override
// called every time we execute a Postscript command in data streams
// (dataPointer/streamSize) gives indicator of amount decoded but page can
// contain multiple streams
public boolean checkForExitRequest(final int dataPointer, final int streamSize) {
//gracefully allow us to fail if over certain time to decode
final long timeElapsed = (System.currentTimeMillis() - timeAtStart);
System.out.println("Mill-Seconds elapsed=" + timeElapsed);
if (timeElapsed > 1_500) {
userFailedPage = true;
return true;
} else {
return false;
}
}
@Override
public void finishedPageDecoding(final int rawPage) {
System.out.println("----Completed page " + rawPage);
}
@Override
//called when we start decoding page
public void startedPageDecoding(final int rawPage) {
System.out.println("----Started page " + rawPage);
// get the current time
timeAtStart = System.currentTimeMillis();
}
}
|