equal
deleted
inserted
replaced
131 throw new IOException("Missing input resource!"); |
131 throw new IOException("Missing input resource!"); |
132 } |
132 } |
133 if (file.exists() && !append) { |
133 if (file.exists() && !append) { |
134 file.delete(); |
134 file.delete(); |
135 } |
135 } |
136 InputStream in = location.openStream(); |
136 try (InputStream in = location.openStream(); |
137 FileOutputStream out = new FileOutputStream(file, append); |
137 FileOutputStream out = new FileOutputStream(file, append)) { |
138 byte[] buffer = new byte[1024]; |
138 |
139 int len; |
139 byte[] buffer = new byte[1024]; |
140 while ((len = in.read(buffer)) != -1) { |
140 int len; |
141 out.write(buffer, 0, len); |
141 while ((len = in.read(buffer)) != -1) { |
142 } |
142 out.write(buffer, 0, len); |
143 out.close(); |
143 } |
144 in.close(); |
144 } |
145 file.setReadOnly(); |
145 file.setReadOnly(); |
146 file.setReadable(true, false); |
146 file.setReadable(true, false); |
147 } |
147 } |
148 |
148 |
149 public static void copyFile(File sourceFile, File destFile) |
149 public static void copyFile(File sourceFile, File destFile) |
152 |
152 |
153 //recreate the file as existing copy may have weird permissions |
153 //recreate the file as existing copy may have weird permissions |
154 destFile.delete(); |
154 destFile.delete(); |
155 destFile.createNewFile(); |
155 destFile.createNewFile(); |
156 |
156 |
157 FileChannel source = null; |
157 try (FileChannel source = new FileInputStream(sourceFile).getChannel(); |
158 FileChannel destination = null; |
158 FileChannel destination = |
159 source = new FileInputStream(sourceFile).getChannel(); |
159 new FileOutputStream(destFile).getChannel()) { |
160 destination = new FileOutputStream(destFile).getChannel(); |
160 |
161 if (destination != null && source != null) { |
161 if (destination != null && source != null) { |
162 destination.transferFrom(source, 0, source.size()); |
162 destination.transferFrom(source, 0, source.size()); |
163 } |
163 } |
164 if (source != null) { |
|
165 source.close(); |
|
166 } |
|
167 if (destination != null) { |
|
168 destination.close(); |
|
169 } |
164 } |
170 |
165 |
171 //preserve executable bit! |
166 //preserve executable bit! |
172 if (sourceFile.canExecute()) { |
167 if (sourceFile.canExecute()) { |
173 destFile.setExecutable(true, false); |
168 destFile.setExecutable(true, false); |