/** * Deletes a style from the configuration. * * @param style The configuration for the style. * @param purge Whether to delete the file from disk. */ public void deleteStyle(StyleInfo style, boolean purgeFile) throws IOException { synchronized (styleCache) { if (purgeFile) { File styleFile = dataDir().findStyleSldFile(style); if (styleFile != null && styleFile.exists()) { styleFile.delete(); } } } }
/** * Reads a raw style from persistence. * * @param style The configuration for the style. * @return A reader for the style. */ public BufferedReader readStyle(StyleInfo style) throws IOException { Resource styleResource = dataDir().style(style); if (styleResource == null) { throw new IOException("No such resource: " + style.getFilename()); } return new BufferedReader(new InputStreamReader(styleResource.in())); }
/** * Writes a raw style to configuration. * * @param style The configuration for the style. * @param in input stream representing the raw a style. */ public void writeStyle(StyleInfo style, InputStream in) throws IOException { synchronized (styleCache) { Resource styleFile = dataDir().style(style); writeStyle(in, styleFile); clear(style); } }
/** * Serializes a style to configuration optionally formatting the style when writing it. * * @param info The configuration for the style. * @param style The style object. * @param format Whether to format the style */ public void writeSLD(StyleInfo info, StyledLayerDescriptor style, boolean format) throws IOException { synchronized (sldCache) { Resource styleFile = dataDir().style(info); BufferedOutputStream out = new BufferedOutputStream(styleFile.out()); try { Styles.handler(info.getFormat()) .encode(style, info.getFormatVersion(), format, out); clear(info); } finally { out.close(); } } }
/** * Serializes a style to configuration optionally formatting the style when writing it. * * @param info The configuration for the style. * @param style The style object. * @param format Whether to format the style */ public void writeStyle(StyleInfo info, Style style, boolean format) throws IOException { synchronized (styleCache) { Resource styleFile = dataDir().style(info); BufferedOutputStream out = new BufferedOutputStream(styleFile.out()); try { Styles.handler(info.getFormat()) .encode(Styles.sld(style), info.getFormatVersion(), format, out); clear(info); } finally { out.close(); } } }