You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UnpackedObjectTest.java 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. /*
  2. * Copyright (C) 2010, Google Inc.
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.storage.file;
  44. import static org.junit.Assert.assertEquals;
  45. import static org.junit.Assert.assertFalse;
  46. import static org.junit.Assert.assertNotNull;
  47. import static org.junit.Assert.assertTrue;
  48. import static org.junit.Assert.fail;
  49. import java.io.ByteArrayInputStream;
  50. import java.io.ByteArrayOutputStream;
  51. import java.io.File;
  52. import java.io.FileInputStream;
  53. import java.io.FileOutputStream;
  54. import java.io.IOException;
  55. import java.io.InputStream;
  56. import java.text.MessageFormat;
  57. import java.util.Arrays;
  58. import java.util.zip.DeflaterOutputStream;
  59. import org.eclipse.jgit.JGitText;
  60. import org.eclipse.jgit.errors.CorruptObjectException;
  61. import org.eclipse.jgit.errors.LargeObjectException;
  62. import org.eclipse.jgit.junit.JGitTestUtil;
  63. import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
  64. import org.eclipse.jgit.junit.TestRng;
  65. import org.eclipse.jgit.lib.Constants;
  66. import org.eclipse.jgit.lib.ObjectId;
  67. import org.eclipse.jgit.lib.ObjectInserter;
  68. import org.eclipse.jgit.lib.ObjectLoader;
  69. import org.eclipse.jgit.lib.ObjectStream;
  70. import org.eclipse.jgit.util.FileUtils;
  71. import org.eclipse.jgit.util.IO;
  72. import org.junit.After;
  73. import org.junit.Before;
  74. import org.junit.Test;
  75. public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
  76. private int streamThreshold = 16 * 1024;
  77. private TestRng rng;
  78. private FileRepository repo;
  79. private WindowCursor wc;
  80. private TestRng getRng() {
  81. if (rng == null)
  82. rng = new TestRng(JGitTestUtil.getName());
  83. return rng;
  84. }
  85. @Before
  86. public void setUp() throws Exception {
  87. super.setUp();
  88. WindowCacheConfig cfg = new WindowCacheConfig();
  89. cfg.setStreamFileThreshold(streamThreshold);
  90. WindowCache.reconfigure(cfg);
  91. repo = createBareRepository();
  92. wc = (WindowCursor) repo.newObjectReader();
  93. }
  94. @After
  95. public void tearDown() throws Exception {
  96. if (wc != null)
  97. wc.release();
  98. WindowCache.reconfigure(new WindowCacheConfig());
  99. super.tearDown();
  100. }
  101. @Test
  102. public void testStandardFormat_SmallObject() throws Exception {
  103. final int type = Constants.OBJ_BLOB;
  104. byte[] data = getRng().nextBytes(300);
  105. byte[] gz = compressStandardFormat(type, data);
  106. ObjectId id = ObjectId.zeroId();
  107. ObjectLoader ol = UnpackedObject.open(new ByteArrayInputStream(gz),
  108. path(id), id, wc);
  109. assertNotNull("created loader", ol);
  110. assertEquals(type, ol.getType());
  111. assertEquals(data.length, ol.getSize());
  112. assertFalse("is not large", ol.isLarge());
  113. assertTrue("same content", Arrays.equals(data, ol.getCachedBytes()));
  114. ObjectStream in = ol.openStream();
  115. assertNotNull("have stream", in);
  116. assertEquals(type, in.getType());
  117. assertEquals(data.length, in.getSize());
  118. byte[] data2 = new byte[data.length];
  119. IO.readFully(in, data2, 0, data.length);
  120. assertTrue("same content", Arrays.equals(data2, data));
  121. assertEquals("stream at EOF", -1, in.read());
  122. in.close();
  123. }
  124. @Test
  125. public void testStandardFormat_LargeObject() throws Exception {
  126. final int type = Constants.OBJ_BLOB;
  127. byte[] data = getRng().nextBytes(streamThreshold + 5);
  128. ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
  129. write(id, compressStandardFormat(type, data));
  130. ObjectLoader ol;
  131. {
  132. FileInputStream fs = new FileInputStream(path(id));
  133. try {
  134. ol = UnpackedObject.open(fs, path(id), id, wc);
  135. } finally {
  136. fs.close();
  137. }
  138. }
  139. assertNotNull("created loader", ol);
  140. assertEquals(type, ol.getType());
  141. assertEquals(data.length, ol.getSize());
  142. assertTrue("is large", ol.isLarge());
  143. try {
  144. ol.getCachedBytes();
  145. fail("Should have thrown LargeObjectException");
  146. } catch (LargeObjectException tooBig) {
  147. assertEquals(MessageFormat.format(
  148. JGitText.get().largeObjectException, id.name()), tooBig
  149. .getMessage());
  150. }
  151. ObjectStream in = ol.openStream();
  152. assertNotNull("have stream", in);
  153. assertEquals(type, in.getType());
  154. assertEquals(data.length, in.getSize());
  155. byte[] data2 = new byte[data.length];
  156. IO.readFully(in, data2, 0, data.length);
  157. assertTrue("same content", Arrays.equals(data2, data));
  158. assertEquals("stream at EOF", -1, in.read());
  159. in.close();
  160. }
  161. @Test
  162. public void testStandardFormat_NegativeSize() throws Exception {
  163. ObjectId id = ObjectId.zeroId();
  164. byte[] data = getRng().nextBytes(300);
  165. try {
  166. byte[] gz = compressStandardFormat("blob", "-1", data);
  167. UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
  168. fail("Did not throw CorruptObjectException");
  169. } catch (CorruptObjectException coe) {
  170. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  171. id.name(), JGitText.get().corruptObjectNegativeSize), coe
  172. .getMessage());
  173. }
  174. }
  175. @Test
  176. public void testStandardFormat_InvalidType() throws Exception {
  177. ObjectId id = ObjectId.zeroId();
  178. byte[] data = getRng().nextBytes(300);
  179. try {
  180. byte[] gz = compressStandardFormat("not.a.type", "1", data);
  181. UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
  182. fail("Did not throw CorruptObjectException");
  183. } catch (CorruptObjectException coe) {
  184. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  185. id.name(), JGitText.get().corruptObjectInvalidType), coe
  186. .getMessage());
  187. }
  188. }
  189. @Test
  190. public void testStandardFormat_NoHeader() throws Exception {
  191. ObjectId id = ObjectId.zeroId();
  192. byte[] data = {};
  193. try {
  194. byte[] gz = compressStandardFormat("", "", data);
  195. UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
  196. fail("Did not throw CorruptObjectException");
  197. } catch (CorruptObjectException coe) {
  198. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  199. id.name(), JGitText.get().corruptObjectNoHeader), coe
  200. .getMessage());
  201. }
  202. }
  203. @Test
  204. public void testStandardFormat_GarbageAfterSize() throws Exception {
  205. ObjectId id = ObjectId.zeroId();
  206. byte[] data = getRng().nextBytes(300);
  207. try {
  208. byte[] gz = compressStandardFormat("blob", "1foo", data);
  209. UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
  210. fail("Did not throw CorruptObjectException");
  211. } catch (CorruptObjectException coe) {
  212. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  213. id.name(), JGitText.get().corruptObjectGarbageAfterSize),
  214. coe.getMessage());
  215. }
  216. }
  217. @Test
  218. public void testStandardFormat_SmallObject_CorruptZLibStream()
  219. throws Exception {
  220. ObjectId id = ObjectId.zeroId();
  221. byte[] data = getRng().nextBytes(300);
  222. try {
  223. byte[] gz = compressStandardFormat(Constants.OBJ_BLOB, data);
  224. for (int i = 5; i < gz.length; i++)
  225. gz[i] = 0;
  226. UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
  227. fail("Did not throw CorruptObjectException");
  228. } catch (CorruptObjectException coe) {
  229. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  230. id.name(), JGitText.get().corruptObjectBadStream), coe
  231. .getMessage());
  232. }
  233. }
  234. @Test
  235. public void testStandardFormat_SmallObject_TruncatedZLibStream()
  236. throws Exception {
  237. ObjectId id = ObjectId.zeroId();
  238. byte[] data = getRng().nextBytes(300);
  239. try {
  240. byte[] gz = compressStandardFormat(Constants.OBJ_BLOB, data);
  241. byte[] tr = new byte[gz.length - 1];
  242. System.arraycopy(gz, 0, tr, 0, tr.length);
  243. UnpackedObject.open(new ByteArrayInputStream(tr), path(id), id, wc);
  244. fail("Did not throw CorruptObjectException");
  245. } catch (CorruptObjectException coe) {
  246. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  247. id.name(), JGitText.get().corruptObjectBadStream), coe
  248. .getMessage());
  249. }
  250. }
  251. @Test
  252. public void testStandardFormat_SmallObject_TrailingGarbage()
  253. throws Exception {
  254. ObjectId id = ObjectId.zeroId();
  255. byte[] data = getRng().nextBytes(300);
  256. try {
  257. byte[] gz = compressStandardFormat(Constants.OBJ_BLOB, data);
  258. byte[] tr = new byte[gz.length + 1];
  259. System.arraycopy(gz, 0, tr, 0, gz.length);
  260. UnpackedObject.open(new ByteArrayInputStream(tr), path(id), id, wc);
  261. fail("Did not throw CorruptObjectException");
  262. } catch (CorruptObjectException coe) {
  263. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  264. id.name(), JGitText.get().corruptObjectBadStream), coe
  265. .getMessage());
  266. }
  267. }
  268. @Test
  269. public void testStandardFormat_LargeObject_CorruptZLibStream()
  270. throws Exception {
  271. final int type = Constants.OBJ_BLOB;
  272. byte[] data = getRng().nextBytes(streamThreshold + 5);
  273. ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
  274. byte[] gz = compressStandardFormat(type, data);
  275. gz[gz.length - 1] = 0;
  276. gz[gz.length - 2] = 0;
  277. write(id, gz);
  278. ObjectLoader ol;
  279. {
  280. FileInputStream fs = new FileInputStream(path(id));
  281. try {
  282. ol = UnpackedObject.open(fs, path(id), id, wc);
  283. } finally {
  284. fs.close();
  285. }
  286. }
  287. try {
  288. byte[] tmp = new byte[data.length];
  289. InputStream in = ol.openStream();
  290. try {
  291. IO.readFully(in, tmp, 0, tmp.length);
  292. } finally {
  293. in.close();
  294. }
  295. fail("Did not throw CorruptObjectException");
  296. } catch (CorruptObjectException coe) {
  297. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  298. id.name(), JGitText.get().corruptObjectBadStream), coe
  299. .getMessage());
  300. }
  301. }
  302. @Test
  303. public void testStandardFormat_LargeObject_TruncatedZLibStream()
  304. throws Exception {
  305. final int type = Constants.OBJ_BLOB;
  306. byte[] data = getRng().nextBytes(streamThreshold + 5);
  307. ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
  308. byte[] gz = compressStandardFormat(type, data);
  309. byte[] tr = new byte[gz.length - 1];
  310. System.arraycopy(gz, 0, tr, 0, tr.length);
  311. write(id, tr);
  312. ObjectLoader ol;
  313. {
  314. FileInputStream fs = new FileInputStream(path(id));
  315. try {
  316. ol = UnpackedObject.open(fs, path(id), id, wc);
  317. } finally {
  318. fs.close();
  319. }
  320. }
  321. byte[] tmp = new byte[data.length];
  322. InputStream in = ol.openStream();
  323. IO.readFully(in, tmp, 0, tmp.length);
  324. try {
  325. in.close();
  326. fail("close did not throw CorruptObjectException");
  327. } catch (CorruptObjectException coe) {
  328. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  329. id.name(), JGitText.get().corruptObjectBadStream), coe
  330. .getMessage());
  331. }
  332. }
  333. @Test
  334. public void testStandardFormat_LargeObject_TrailingGarbage()
  335. throws Exception {
  336. final int type = Constants.OBJ_BLOB;
  337. byte[] data = getRng().nextBytes(streamThreshold + 5);
  338. ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
  339. byte[] gz = compressStandardFormat(type, data);
  340. byte[] tr = new byte[gz.length + 1];
  341. System.arraycopy(gz, 0, tr, 0, gz.length);
  342. write(id, tr);
  343. ObjectLoader ol;
  344. {
  345. FileInputStream fs = new FileInputStream(path(id));
  346. try {
  347. ol = UnpackedObject.open(fs, path(id), id, wc);
  348. } finally {
  349. fs.close();
  350. }
  351. }
  352. byte[] tmp = new byte[data.length];
  353. InputStream in = ol.openStream();
  354. IO.readFully(in, tmp, 0, tmp.length);
  355. try {
  356. in.close();
  357. fail("close did not throw CorruptObjectException");
  358. } catch (CorruptObjectException coe) {
  359. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  360. id.name(), JGitText.get().corruptObjectBadStream), coe
  361. .getMessage());
  362. }
  363. }
  364. @Test
  365. public void testPackFormat_SmallObject() throws Exception {
  366. final int type = Constants.OBJ_BLOB;
  367. byte[] data = getRng().nextBytes(300);
  368. byte[] gz = compressPackFormat(type, data);
  369. ObjectId id = ObjectId.zeroId();
  370. ObjectLoader ol = UnpackedObject.open(new ByteArrayInputStream(gz),
  371. path(id), id, wc);
  372. assertNotNull("created loader", ol);
  373. assertEquals(type, ol.getType());
  374. assertEquals(data.length, ol.getSize());
  375. assertFalse("is not large", ol.isLarge());
  376. assertTrue("same content", Arrays.equals(data, ol.getCachedBytes()));
  377. ObjectStream in = ol.openStream();
  378. assertNotNull("have stream", in);
  379. assertEquals(type, in.getType());
  380. assertEquals(data.length, in.getSize());
  381. byte[] data2 = new byte[data.length];
  382. IO.readFully(in, data2, 0, data.length);
  383. assertTrue("same content", Arrays.equals(data, ol.getCachedBytes()));
  384. in.close();
  385. }
  386. @Test
  387. public void testPackFormat_LargeObject() throws Exception {
  388. final int type = Constants.OBJ_BLOB;
  389. byte[] data = getRng().nextBytes(streamThreshold + 5);
  390. ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
  391. write(id, compressPackFormat(type, data));
  392. ObjectLoader ol;
  393. {
  394. FileInputStream fs = new FileInputStream(path(id));
  395. try {
  396. ol = UnpackedObject.open(fs, path(id), id, wc);
  397. } finally {
  398. fs.close();
  399. }
  400. }
  401. assertNotNull("created loader", ol);
  402. assertEquals(type, ol.getType());
  403. assertEquals(data.length, ol.getSize());
  404. assertTrue("is large", ol.isLarge());
  405. try {
  406. ol.getCachedBytes();
  407. fail("Should have thrown LargeObjectException");
  408. } catch (LargeObjectException tooBig) {
  409. assertEquals(MessageFormat.format(
  410. JGitText.get().largeObjectException, id.name()), tooBig
  411. .getMessage());
  412. }
  413. ObjectStream in = ol.openStream();
  414. assertNotNull("have stream", in);
  415. assertEquals(type, in.getType());
  416. assertEquals(data.length, in.getSize());
  417. byte[] data2 = new byte[data.length];
  418. IO.readFully(in, data2, 0, data.length);
  419. assertTrue("same content", Arrays.equals(data2, data));
  420. assertEquals("stream at EOF", -1, in.read());
  421. in.close();
  422. }
  423. @Test
  424. public void testPackFormat_DeltaNotAllowed() throws Exception {
  425. ObjectId id = ObjectId.zeroId();
  426. byte[] data = getRng().nextBytes(300);
  427. try {
  428. byte[] gz = compressPackFormat(Constants.OBJ_OFS_DELTA, data);
  429. UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
  430. fail("Did not throw CorruptObjectException");
  431. } catch (CorruptObjectException coe) {
  432. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  433. id.name(), JGitText.get().corruptObjectInvalidType), coe
  434. .getMessage());
  435. }
  436. try {
  437. byte[] gz = compressPackFormat(Constants.OBJ_REF_DELTA, data);
  438. UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
  439. fail("Did not throw CorruptObjectException");
  440. } catch (CorruptObjectException coe) {
  441. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  442. id.name(), JGitText.get().corruptObjectInvalidType), coe
  443. .getMessage());
  444. }
  445. try {
  446. byte[] gz = compressPackFormat(Constants.OBJ_TYPE_5, data);
  447. UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
  448. fail("Did not throw CorruptObjectException");
  449. } catch (CorruptObjectException coe) {
  450. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  451. id.name(), JGitText.get().corruptObjectInvalidType), coe
  452. .getMessage());
  453. }
  454. try {
  455. byte[] gz = compressPackFormat(Constants.OBJ_EXT, data);
  456. UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
  457. fail("Did not throw CorruptObjectException");
  458. } catch (CorruptObjectException coe) {
  459. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  460. id.name(), JGitText.get().corruptObjectInvalidType), coe
  461. .getMessage());
  462. }
  463. }
  464. private byte[] compressStandardFormat(int type, byte[] data)
  465. throws IOException {
  466. String typeString = Constants.typeString(type);
  467. String length = String.valueOf(data.length);
  468. return compressStandardFormat(typeString, length, data);
  469. }
  470. private byte[] compressStandardFormat(String type, String length,
  471. byte[] data) throws IOException {
  472. ByteArrayOutputStream out = new ByteArrayOutputStream();
  473. DeflaterOutputStream d = new DeflaterOutputStream(out);
  474. d.write(Constants.encodeASCII(type));
  475. d.write(' ');
  476. d.write(Constants.encodeASCII(length));
  477. d.write(0);
  478. d.write(data);
  479. d.finish();
  480. return out.toByteArray();
  481. }
  482. private byte[] compressPackFormat(int type, byte[] data) throws IOException {
  483. byte[] hdr = new byte[64];
  484. int rawLength = data.length;
  485. int nextLength = rawLength >>> 4;
  486. hdr[0] = (byte) ((nextLength > 0 ? 0x80 : 0x00) | (type << 4) | (rawLength & 0x0F));
  487. rawLength = nextLength;
  488. int n = 1;
  489. while (rawLength > 0) {
  490. nextLength >>>= 7;
  491. hdr[n++] = (byte) ((nextLength > 0 ? 0x80 : 0x00) | (rawLength & 0x7F));
  492. rawLength = nextLength;
  493. }
  494. final ByteArrayOutputStream out = new ByteArrayOutputStream();
  495. out.write(hdr, 0, n);
  496. DeflaterOutputStream d = new DeflaterOutputStream(out);
  497. d.write(data);
  498. d.finish();
  499. return out.toByteArray();
  500. }
  501. private File path(ObjectId id) {
  502. return repo.getObjectDatabase().fileFor(id);
  503. }
  504. private void write(ObjectId id, byte[] data) throws IOException {
  505. File path = path(id);
  506. FileUtils.mkdirs(path.getParentFile());
  507. FileOutputStream out = new FileOutputStream(path);
  508. try {
  509. out.write(data);
  510. } finally {
  511. out.close();
  512. }
  513. }
  514. }