(@NotNull String resourcePath, boolean replace)
| 181 | } |
| 182 | |
| 183 | @Override |
| 184 | public void saveResource(@NotNull String resourcePath, boolean replace) { |
| 185 | if (resourcePath == null || resourcePath.equals("")) { |
| 186 | throw new IllegalArgumentException("ResourcePath cannot be null or empty"); |
| 187 | } |
| 188 | |
| 189 | resourcePath = resourcePath.replace('\\', '/'); |
| 190 | InputStream in = getResource(resourcePath); |
| 191 | if (in == null) { |
| 192 | throw new IllegalArgumentException("The embedded resource '" + resourcePath + "' cannot be found in " + file); |
| 193 | } |
| 194 | |
| 195 | File outFile = new File(dataFolder, resourcePath); |
| 196 | int lastIndex = resourcePath.lastIndexOf('/'); |
| 197 | File outDir = new File(dataFolder, resourcePath.substring(0, lastIndex >= 0 ? lastIndex : 0)); |
| 198 | |
| 199 | if (!outDir.exists()) { |
| 200 | outDir.mkdirs(); |
| 201 | } |
| 202 | |
| 203 | try { |
| 204 | if (!outFile.exists() || replace) { |
| 205 | OutputStream out = new FileOutputStream(outFile); |
| 206 | byte[] buf = new byte[1024]; |
| 207 | int len; |
| 208 | while ((len = in.read(buf)) > 0) { |
| 209 | out.write(buf, 0, len); |
| 210 | } |
| 211 | out.close(); |
| 212 | in.close(); |
| 213 | } else { |
| 214 | logger.log(Level.WARNING, "Could not save " + outFile.getName() + " to " + outFile + " because " + outFile.getName() + " already exists."); |
| 215 | } |
| 216 | } catch (IOException ex) { |
| 217 | logger.log(Level.SEVERE, "Could not save " + outFile.getName() + " to " + outFile, ex); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | @Nullable |
| 222 | @Override |
no test coverage detected