@Test public void shouldNotDeleteFileAfterA500() throws IOException { when(client.send(anyString())).thenReturn(500); sendStoredExceptions.processFiles(); verify(client).send("hello world"); verify(file, never()).delete(); }
void processFiles() { File[] files = storage.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(RaygunOnFailedSendOfflineStorageHandler.fileExtension); } }); if (files == null) { return; } for (File file : files) { InputStream inputStream = null; ByteArrayOutputStream outputStream = null; try { inputStream = getInputStream(file); outputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[(int) file.length()]; int length; while ((length = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, length); } inputStream.close(); int reponseCode = client.send(outputStream.toString("UTF-8")); if (deleteOnStatusCodes.contains(reponseCode)) { file.delete(); } } catch (IOException e) { Logger.getLogger("Raygun4Java").warning("exception processing offline payload: " + e.getMessage()); return; } finally { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { Logger.getLogger("Raygun4Java").warning("exception closing outputStream: " + e.getMessage()); } } if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { Logger.getLogger("Raygun4Java").warning("exception closing inputStream: " + e.getMessage()); } } } } }
RaygunSendStoredExceptions implements Runnable { void processFiles() { File[] files = storage.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(RaygunOnFailedSendOfflineStorageHandler.fileExtension); } }); if (files == null) { return; } for (File file : files) { InputStream inputStream = null; ByteArrayOutputStream outputStream = null; try { inputStream = getInputStream(file); outputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[(int) file.length()]; int length; while ((length = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, length); } inputStream.close(); int reponseCode = client.send(outputStream.toString("UTF-8")); if (deleteOnStatusCodes.contains(reponseCode)) { file.delete(); } } catch (IOException e) { Logger.getLogger("Raygun4Java").warning("exception processing offline payload: " + e.getMessage()); return; } finally { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { Logger.getLogger("Raygun4Java").warning("exception closing outputStream: " + e.getMessage()); } } if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { Logger.getLogger("Raygun4Java").warning("exception closing inputStream: " + e.getMessage()); } } } } } }
RaygunSendStoredExceptions implements Runnable { void processFiles() { File[] files = storage.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(RaygunOnFailedSendOfflineStorageHandler.fileExtension); } }); if (files == null) { return; } for (File file : files) { InputStream inputStream = null; ByteArrayOutputStream outputStream = null; try { inputStream = getInputStream(file); outputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[(int) file.length()]; int length; while ((length = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, length); } inputStream.close(); int reponseCode = client.send(outputStream.toString("UTF-8")); if (deleteOnStatusCodes.contains(reponseCode)) { file.delete(); } } catch (IOException e) { Logger.getLogger("Raygun4Java").warning("exception processing offline payload: " + e.getMessage()); return; } finally { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { Logger.getLogger("Raygun4Java").warning("exception closing outputStream: " + e.getMessage()); } } if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { Logger.getLogger("Raygun4Java").warning("exception closing inputStream: " + e.getMessage()); } } } } } RaygunSendStoredExceptions(RaygunClient client, File storage); }
RaygunSendStoredExceptions implements Runnable { void processFiles() { File[] files = storage.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(RaygunOnFailedSendOfflineStorageHandler.fileExtension); } }); if (files == null) { return; } for (File file : files) { InputStream inputStream = null; ByteArrayOutputStream outputStream = null; try { inputStream = getInputStream(file); outputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[(int) file.length()]; int length; while ((length = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, length); } inputStream.close(); int reponseCode = client.send(outputStream.toString("UTF-8")); if (deleteOnStatusCodes.contains(reponseCode)) { file.delete(); } } catch (IOException e) { Logger.getLogger("Raygun4Java").warning("exception processing offline payload: " + e.getMessage()); return; } finally { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { Logger.getLogger("Raygun4Java").warning("exception closing outputStream: " + e.getMessage()); } } if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { Logger.getLogger("Raygun4Java").warning("exception closing inputStream: " + e.getMessage()); } } } } } RaygunSendStoredExceptions(RaygunClient client, File storage); void run(); }
RaygunSendStoredExceptions implements Runnable { void processFiles() { File[] files = storage.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(RaygunOnFailedSendOfflineStorageHandler.fileExtension); } }); if (files == null) { return; } for (File file : files) { InputStream inputStream = null; ByteArrayOutputStream outputStream = null; try { inputStream = getInputStream(file); outputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[(int) file.length()]; int length; while ((length = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, length); } inputStream.close(); int reponseCode = client.send(outputStream.toString("UTF-8")); if (deleteOnStatusCodes.contains(reponseCode)) { file.delete(); } } catch (IOException e) { Logger.getLogger("Raygun4Java").warning("exception processing offline payload: " + e.getMessage()); return; } finally { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { Logger.getLogger("Raygun4Java").warning("exception closing outputStream: " + e.getMessage()); } } if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { Logger.getLogger("Raygun4Java").warning("exception closing inputStream: " + e.getMessage()); } } } } } RaygunSendStoredExceptions(RaygunClient client, File storage); void run();  }