public LineWriter(final WritableResource writableResource) { super(new OutputStreamWriter(writableResource.write(), CHARSET)); this.writableResource = writableResource; }
private void save(final WritableResource output, final String string) { try (BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(output.write(), StandardCharsets.UTF_8));) { writer.write(string); } catch (final Exception e) { throw new CoreException("Could not save wkt file {}", output.getName(), e); } } }
@Test public void testSerialization() throws IOException, ClassNotFoundException { final MultiMap<Polygon, Polygon> map = getMultiMap(); final WritableResource out = new ByteArrayResource(); final ObjectOutputStream outStream = new ObjectOutputStream(out.write()); outStream.writeObject(map); Streams.close(outStream); try (ObjectInputStream inStream = new ObjectInputStream(out.read())) { @SuppressWarnings("unchecked") final MultiMap<Polygon, Polygon> result = (MultiMap<Polygon, Polygon>) inStream .readObject(); Assert.assertEquals(map, result); } catch (final Exception e) { throw e; } } }
/** * Write to this resource and close it. * * @param value * The value to write. */ default void writeAndClose(final String value) { try (BufferedWriter writer = writer()) { writer.write(value); } catch (final Exception e) { throw new CoreException("Could not write to {}", this, e); } }
public void update(final Resource josmOsmFile, final WritableResource osmFile) { final StringList result = new StringList(); for (final String line : josmOsmFile.lines()) { String replaced = line; for (final Tuple<String, String> replacement : this.replacements) { replaced = replaced.replaceAll(replacement.getFirst(), replacement.getSecond()); } result.add(replaced); } osmFile.writeAndClose(result.join(System.lineSeparator())); } }
@Test public void testSerialization() throws ClassNotFoundException { final MultiPolygon map = new MultiPolygon(MultiMapTest.getMultiMap()); final WritableResource out = new ByteArrayResource(); try (ObjectOutputStream outStream = new ObjectOutputStream(out.write())) { outStream.writeObject(map); } catch (final IOException e) { throw new CoreException("Unable to write to {}", out, e); } try (ObjectInputStream inStream = new ObjectInputStream(out.read())) { final MultiPolygon result = (MultiPolygon) inStream.readObject(); Assert.assertEquals(map, result); } catch (final IOException e) { throw new CoreException("Unable to read from {}", out, e); } }
/** * Writes to a {@link WritableResource} the CountryShardListCache. The resulting resource can be * used to initialize another CountryShardListCache. * * @param output * The {@link WritableResource} where the CountryToShardListCache will be written. */ public void save(final WritableResource output) { try (SafeBufferedWriter writer = output.writer()) { this.countryToShards.forEach((country, shardList) -> { final List<String> shardNames = shardList.stream() .map(slippyTile -> slippyTile.getName()).collect(Collectors.toList()); writer.writeLine(String.format("%s%s%s", country, DELIMITER, shardNames) .replace("[", "").replace("]", "")); }); } catch (final Exception e) { throw new CoreException("Error while writing CountryToShardListCache to file!", e); } }
resource.writeAndClose(protoAtlas.toByteArray());
public BinaryChangeSetSerializer(final WritableResource resourceToWriteInto) throws IOException { this.resource = new ObjectOutputStream(resourceToWriteInto.write()); }
@Override public void accept(final FeatureChange featureChange, final WritableResource resource) { try (Writer writer = resource.writer()) { jsonSerializer.toJson(featureChange, writer); } catch (final IOException e) { throw new CoreException("Could not save FeatureChange to resource {}", resource.getName(), e); } }
protected void save(final WritableResource resource) { final BufferedWriter writer = resource.writer(); try { this.save(writer); } catch (final Exception e) { Streams.close(writer); throw e; } Streams.close(writer); }
public JsonWriter(final WritableResource resource) { this.writer = new BufferedWriter( new OutputStreamWriter(resource.write(), StandardCharsets.UTF_8)); }
/** * @return A {@link BufferedWriter} on this resource. */ default SafeBufferedWriter writer() { return new SafeBufferedWriter(new OutputStreamWriter(write(), StandardCharsets.UTF_8)); } }
/** * Write to this resource and close it. * * @param value * The value to write. */ default void writeAndClose(final byte[] value) { try (BufferedOutputStream output = new BufferedOutputStream(write())) { output.write(value); } catch (final Exception e) { throw new CoreException("Could not write to {}", this, e); } }
/** * Writes the string value of this {@link CheckFlag} to the {@link WritableResource} * * @param writableResource * a {@link WritableResource} to write to */ public void save(final WritableResource writableResource) { try (BufferedWriter out = new BufferedWriter( new OutputStreamWriter(writableResource.write(), StandardCharsets.UTF_8))) { out.write(toString()); } catch (final Exception e) { throw new CoreException("Could not save Check Flag to {}", e, writableResource); } }
public void save(final WritableResource output) { final BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(output.write(), StandardCharsets.UTF_8)); try { writer.write(this.jsonObject.toString()); Streams.close(writer); } catch (final Exception e) { Streams.close(writer); throw new CoreException("Could not save geojson object", e); } }
/** * Copy all the contents of this {@link Resource} to a {@link WritableResource} * * @param output * The output {@link WritableResource} */ default void copyTo(final WritableResource output) { try (InputStream inputStream = read(); OutputStream outputStream = output.write()) { IOUtils.copy(inputStream, outputStream); } catch (final Exception e) { throw new CoreException("Unable to copy {} to {}.", this, output, e); } }
/** * <pre> * Write country boundary map and the grid index into a text file using WKT format. * Output will have the format below, where each country will be on a new line: * * [ISO-Country-code]||[Country boundary Multi-Polygon]# * --[Grid Index Envelope Polygon]--[grid-cell-1]==[grid-cell-n]== * </pre> * * @param resource * The output {@link WritableResource} * @throws IOException * {@link IOException} */ public void writeToFile(final WritableResource resource) throws IOException { try (BufferedWriter output = new BufferedWriter( new OutputStreamWriter(resource.write(), StandardCharsets.UTF_8))) { // Write country boundaries this.writeCountryBoundaries(output); // Write grid index cells this.writeGridIndex(output); } }
@Override public void saveAsList(final WritableResource resource) { final BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(resource.write(), StandardCharsets.UTF_8)); try { writer.write(this.toString()); Streams.close(writer); } catch (final IOException e) { Streams.close(writer); throw new CoreException("Could not save atlas as list", e); } }