/** * Saves the configuration to the root cache directory * * @param config * @throws IOException * @throws ConfigurationException */ public void saveConfig(DiskQuotaConfig config) throws IOException, ConfigurationException { if (!resourceProvider.hasOutput()) { log.error("Unable to save DiskQuota to resource :" + resourceProvider.getLocation()); return; } XStream xStream = getConfiguredXStream(new GeoWebCacheXStream()); log.debug("Saving disk quota config to " + resourceProvider.getLocation()); try (OutputStream configOut = resourceProvider.out()) { xStream.toXML(config, new OutputStreamWriter(configOut, "UTF-8")); } catch (RuntimeException e) { log.error("Error saving DiskQuota config to file :" + resourceProvider.getLocation()); } }
/** * Method responsible for writing out the entire GeoWebCacheConfiguration object * * <p>throws an exception if it does not succeed */ private void persistToFile() throws IOException { Assert.isTrue(resourceProvider.hasOutput()); // create the XStream for serializing the configuration XStream xs = getConfiguredXStreamWithContext(new GeoWebCacheXStream(), Context.PERSIST); try (OutputStreamWriter writer = new OutputStreamWriter(resourceProvider.out(), "UTF-8")) { // set version to latest String currentSchemaVersion = getCurrentSchemaVersion(); getGwcConfig().setVersion(currentSchemaVersion); writer.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); xs.toXML(getGwcConfig(), writer); } catch (UnsupportedEncodingException uee) { throw new IOException(uee.getMessage(), uee); } catch (FileNotFoundException fnfe) { throw fnfe; } catch (IOException e) { throw (IOException) new IOException( "Error writing to " + resourceProvider.getId() + ": " + e.getMessage()) .initCause(e); } log.info("Wrote configuration to " + resourceProvider.getId()); }