DocumentFile implements Document, Closeable { @Override public void delete(final RegionByLine regionByOffset) { try { tryToDeleteFromFile(mapToRegionByOffset(regionByOffset)); } catch (final IOException e) { LOG.log(Level.WARNING, "An exception occurred when deleting from file " + filePath.toAbsolutePath()); } } DocumentFile(final File file, final Charset charset); @Override void insert(int beginLine, int beginColumn, final String textToInsert); @Override void replace(final RegionByLine regionByLine, final String textToReplace); @Override void delete(final RegionByLine regionByOffset); @Override void close();  }
@Test public void removeTokenShouldSucceed() throws IOException { final String code = "public static void main(final String[] args) {}"; writeContentToTemporaryFile(code); try (DocumentFile documentFile = new DocumentFile(temporaryFile, StandardCharsets.UTF_8)) { documentFile.delete(new RegionByLineImp(0, 0, 24, 30)); } try (FileInputStream stream = new FileInputStream(temporaryFile)) { final String actualContent = new String(readAllBytes(stream)); assertEquals("public static void main(String[] args) {}", actualContent); } }