private static void screenCaptureToFile(AbstractBuild build, AndroidDeviceContext device) throws IOException, InterruptedException { FilePath screencapFile = build.getWorkspace().createTempFile("screencap", ".png"); OutputStream screencapStream = screencapFile.write(); FilterOutputStream replaceFilterStream = new ReplaceFilterOutputStream(screencapStream); device.screenshot(replaceFilterStream); screencapFile.copyTo(new FilePath(build.getArtifactsDir()).child("screencap.png")); }