MCPcopy Create free account
hub / github.com/Teneted/Tenet / saveResource

Method saveResource

src/main/java/org/bukkit/plugin/java/JavaPlugin.java:183–219  ·  view source on GitHub ↗
(@NotNull String resourcePath, boolean replace)

Source from the content-addressed store, hash-verified

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

Callers 1

saveDefaultConfigMethod · 0.95

Calls 9

getResourceMethod · 0.95
equalsMethod · 0.65
replaceMethod · 0.65
readMethod · 0.65
writeMethod · 0.65
closeMethod · 0.65
getNameMethod · 0.65
existsMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected