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.

IgnoreNodeTest.java 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. /*
  2. * Copyright (C) 2010, Red Hat 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.ignore;
  44. import static org.eclipse.jgit.junit.Assert.assertEquals;
  45. import static org.junit.Assert.assertEquals;
  46. import static org.junit.Assert.assertFalse;
  47. import static org.junit.Assert.assertNotNull;
  48. import static org.junit.Assert.assertTrue;
  49. import java.io.ByteArrayInputStream;
  50. import java.io.File;
  51. import java.io.IOException;
  52. import java.io.InputStream;
  53. import java.util.ArrayList;
  54. import java.util.Arrays;
  55. import org.eclipse.jgit.ignore.IgnoreNode.MatchResult;
  56. import org.eclipse.jgit.junit.RepositoryTestCase;
  57. import org.eclipse.jgit.lib.FileMode;
  58. import org.eclipse.jgit.treewalk.FileTreeIterator;
  59. import org.eclipse.jgit.treewalk.TreeWalk;
  60. import org.eclipse.jgit.treewalk.WorkingTreeIterator;
  61. import org.eclipse.jgit.util.FileUtils;
  62. import org.eclipse.jgit.util.SystemReader;
  63. import org.junit.Test;
  64. /**
  65. * Tests ignore node behavior on the local filesystem.
  66. */
  67. public class IgnoreNodeTest extends RepositoryTestCase {
  68. private static final FileMode D = FileMode.TREE;
  69. private static final FileMode F = FileMode.REGULAR_FILE;
  70. private static final boolean ignored = true;
  71. private static final boolean tracked = false;
  72. private TreeWalk walk;
  73. @Test
  74. public void testRules() throws IOException {
  75. writeIgnoreFile(".git/info/exclude", "*~", "/out");
  76. writeIgnoreFile(".gitignore", "*.o", "/config");
  77. writeTrashFile("config/secret", "");
  78. writeTrashFile("mylib.c", "");
  79. writeTrashFile("mylib.c~", "");
  80. writeTrashFile("mylib.o", "");
  81. writeTrashFile("out/object/foo.exe", "");
  82. writeIgnoreFile("src/config/.gitignore", "lex.out");
  83. writeTrashFile("src/config/lex.out", "");
  84. writeTrashFile("src/config/config.c", "");
  85. writeTrashFile("src/config/config.c~", "");
  86. writeTrashFile("src/config/old/lex.out", "");
  87. beginWalk();
  88. assertEntry(F, tracked, ".gitignore");
  89. assertEntry(D, ignored, "config");
  90. assertEntry(F, ignored, "config/secret");
  91. assertEntry(F, tracked, "mylib.c");
  92. assertEntry(F, ignored, "mylib.c~");
  93. assertEntry(F, ignored, "mylib.o");
  94. assertEntry(D, ignored, "out");
  95. assertEntry(D, ignored, "out/object");
  96. assertEntry(F, ignored, "out/object/foo.exe");
  97. assertEntry(D, tracked, "src");
  98. assertEntry(D, tracked, "src/config");
  99. assertEntry(F, tracked, "src/config/.gitignore");
  100. assertEntry(F, tracked, "src/config/config.c");
  101. assertEntry(F, ignored, "src/config/config.c~");
  102. assertEntry(F, ignored, "src/config/lex.out");
  103. assertEntry(D, tracked, "src/config/old");
  104. assertEntry(F, ignored, "src/config/old/lex.out");
  105. endWalk();
  106. }
  107. @Test
  108. public void testNegation() throws IOException {
  109. // ignore all *.o files and ignore all "d" directories
  110. writeIgnoreFile(".gitignore", "*.o", "d");
  111. // negate "ignore" for a/b/keep.o file only
  112. writeIgnoreFile("src/a/b/.gitignore", "!keep.o");
  113. writeTrashFile("src/a/b/keep.o", "");
  114. writeTrashFile("src/a/b/nothere.o", "");
  115. // negate "ignore" for "d"
  116. writeIgnoreFile("src/c/.gitignore", "!d");
  117. // negate "ignore" for c/d/keep.o file only
  118. writeIgnoreFile("src/c/d/.gitignore", "!keep.o");
  119. writeTrashFile("src/c/d/keep.o", "");
  120. writeTrashFile("src/c/d/nothere.o", "");
  121. beginWalk();
  122. assertEntry(F, tracked, ".gitignore");
  123. assertEntry(D, tracked, "src");
  124. assertEntry(D, tracked, "src/a");
  125. assertEntry(D, tracked, "src/a/b");
  126. assertEntry(F, tracked, "src/a/b/.gitignore");
  127. assertEntry(F, tracked, "src/a/b/keep.o");
  128. assertEntry(F, ignored, "src/a/b/nothere.o");
  129. assertEntry(D, tracked, "src/c");
  130. assertEntry(F, tracked, "src/c/.gitignore");
  131. assertEntry(D, tracked, "src/c/d");
  132. assertEntry(F, tracked, "src/c/d/.gitignore");
  133. assertEntry(F, tracked, "src/c/d/keep.o");
  134. // must be ignored: "!d" should not negate *both* "d" and *.o rules!
  135. assertEntry(F, ignored, "src/c/d/nothere.o");
  136. endWalk();
  137. }
  138. /*
  139. * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=407475
  140. */
  141. @Test
  142. public void testNegateAllExceptJavaInSrc() throws IOException {
  143. // ignore all files except from src directory
  144. writeIgnoreFile(".gitignore", "/*", "!/src/");
  145. writeTrashFile("nothere.o", "");
  146. // ignore all files except java
  147. writeIgnoreFile("src/.gitignore", "*", "!*.java");
  148. writeTrashFile("src/keep.java", "");
  149. writeTrashFile("src/nothere.o", "");
  150. writeTrashFile("src/a/nothere.o", "");
  151. beginWalk();
  152. assertEntry(F, ignored, ".gitignore");
  153. assertEntry(F, ignored, "nothere.o");
  154. assertEntry(D, tracked, "src");
  155. assertEntry(F, ignored, "src/.gitignore");
  156. assertEntry(D, ignored, "src/a");
  157. assertEntry(F, ignored, "src/a/nothere.o");
  158. assertEntry(F, tracked, "src/keep.java");
  159. assertEntry(F, ignored, "src/nothere.o");
  160. endWalk();
  161. }
  162. /*
  163. * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=407475
  164. */
  165. @Test
  166. public void testNegationAllExceptJavaInSrcAndExceptChildDirInSrc()
  167. throws IOException {
  168. // ignore all files except from src directory
  169. writeIgnoreFile(".gitignore", "/*", "!/src/");
  170. writeTrashFile("nothere.o", "");
  171. // ignore all files except java in src folder and all children folders.
  172. // Last ignore rule breaks old jgit via bug 407475
  173. writeIgnoreFile("src/.gitignore", "*", "!*.java", "!*/");
  174. writeTrashFile("src/keep.java", "");
  175. writeTrashFile("src/nothere.o", "");
  176. writeTrashFile("src/a/keep.java", "");
  177. writeTrashFile("src/a/keep.o", "");
  178. beginWalk();
  179. assertEntry(F, ignored, ".gitignore");
  180. assertEntry(F, ignored, "nothere.o");
  181. assertEntry(D, tracked, "src");
  182. assertEntry(F, ignored, "src/.gitignore");
  183. assertEntry(D, tracked, "src/a");
  184. assertEntry(F, tracked, "src/a/keep.java");
  185. assertEntry(F, tracked, "src/a/keep.o");
  186. assertEntry(F, tracked, "src/keep.java");
  187. assertEntry(F, ignored, "src/nothere.o");
  188. endWalk();
  189. }
  190. /*
  191. * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=448094
  192. */
  193. @Test
  194. public void testRepeatedNegation() throws IOException {
  195. writeIgnoreFile(".gitignore", "e", "!e", "e", "!e", "e");
  196. writeTrashFile("e/nothere.o", "");
  197. beginWalk();
  198. assertEntry(F, tracked, ".gitignore");
  199. assertEntry(D, ignored, "e");
  200. assertEntry(F, ignored, "e/nothere.o");
  201. endWalk();
  202. }
  203. /*
  204. * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=448094
  205. */
  206. @Test
  207. public void testRepeatedNegationInDifferentFiles1() throws IOException {
  208. writeIgnoreFile(".gitignore", "*.o", "e");
  209. writeIgnoreFile("e/.gitignore", "!e");
  210. writeTrashFile("e/nothere.o", "");
  211. beginWalk();
  212. assertEntry(F, tracked, ".gitignore");
  213. assertEntry(D, ignored, "e");
  214. assertEntry(F, ignored, "e/.gitignore");
  215. assertEntry(F, ignored, "e/nothere.o");
  216. endWalk();
  217. }
  218. /*
  219. * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=448094
  220. */
  221. @Test
  222. public void testRepeatedNegationInDifferentFiles2() throws IOException {
  223. writeIgnoreFile(".gitignore", "*.o", "e");
  224. writeIgnoreFile("a/.gitignore", "!e");
  225. writeTrashFile("a/e/nothere.o", "");
  226. beginWalk();
  227. assertEntry(F, tracked, ".gitignore");
  228. assertEntry(D, tracked, "a");
  229. assertEntry(F, tracked, "a/.gitignore");
  230. assertEntry(D, tracked, "a/e");
  231. assertEntry(F, ignored, "a/e/nothere.o");
  232. endWalk();
  233. }
  234. /*
  235. * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=448094
  236. */
  237. @Test
  238. public void testRepeatedNegationInDifferentFiles3() throws IOException {
  239. writeIgnoreFile(".gitignore", "*.o");
  240. writeIgnoreFile("a/.gitignore", "e");
  241. writeIgnoreFile("a/b/.gitignore", "!e");
  242. writeTrashFile("a/b/e/nothere.o", "");
  243. beginWalk();
  244. assertEntry(F, tracked, ".gitignore");
  245. assertEntry(D, tracked, "a");
  246. assertEntry(F, tracked, "a/.gitignore");
  247. assertEntry(D, tracked, "a/b");
  248. assertEntry(F, tracked, "a/b/.gitignore");
  249. assertEntry(D, tracked, "a/b/e");
  250. assertEntry(F, ignored, "a/b/e/nothere.o");
  251. endWalk();
  252. }
  253. @Test
  254. public void testRepeatedNegationInDifferentFiles4() throws IOException {
  255. writeIgnoreFile(".gitignore", "*.o");
  256. writeIgnoreFile("a/.gitignore", "e");
  257. // Rules are never empty: WorkingTreeIterator optimizes empty rules away
  258. // paranoia check in case this optimization will be removed
  259. writeIgnoreFile("a/b/.gitignore", "#");
  260. writeIgnoreFile("a/b/c/.gitignore", "!e");
  261. writeTrashFile("a/b/c/e/nothere.o", "");
  262. beginWalk();
  263. assertEntry(F, tracked, ".gitignore");
  264. assertEntry(D, tracked, "a");
  265. assertEntry(F, tracked, "a/.gitignore");
  266. assertEntry(D, tracked, "a/b");
  267. assertEntry(F, tracked, "a/b/.gitignore");
  268. assertEntry(D, tracked, "a/b/c");
  269. assertEntry(F, tracked, "a/b/c/.gitignore");
  270. assertEntry(D, tracked, "a/b/c/e");
  271. assertEntry(F, ignored, "a/b/c/e/nothere.o");
  272. endWalk();
  273. }
  274. @Test
  275. public void testEmptyIgnoreNode() {
  276. // Rules are never empty: WorkingTreeIterator optimizes empty files away
  277. // So we have to test it manually in case third party clients use
  278. // IgnoreNode directly.
  279. IgnoreNode node = new IgnoreNode();
  280. assertEquals(MatchResult.CHECK_PARENT, node.isIgnored("", false));
  281. assertEquals(MatchResult.CHECK_PARENT, node.isIgnored("", false, false));
  282. assertEquals(MatchResult.CHECK_PARENT_NEGATE_FIRST_MATCH,
  283. node.isIgnored("", false, true));
  284. }
  285. @Test
  286. public void testEmptyIgnoreRules() throws IOException {
  287. IgnoreNode node = new IgnoreNode();
  288. node.parse(writeToString("", "#", "!", "[[=a=]]"));
  289. assertEquals(new ArrayList<>(), node.getRules());
  290. node.parse(writeToString(" ", " / "));
  291. assertEquals(2, node.getRules().size());
  292. }
  293. @Test
  294. public void testSlashOnlyMatchesDirectory() throws IOException {
  295. writeIgnoreFile(".gitignore", "out/");
  296. writeTrashFile("out", "");
  297. beginWalk();
  298. assertEntry(F, tracked, ".gitignore");
  299. assertEntry(F, tracked, "out");
  300. FileUtils.delete(new File(trash, "out"));
  301. writeTrashFile("out/foo", "");
  302. beginWalk();
  303. assertEntry(F, tracked, ".gitignore");
  304. assertEntry(D, ignored, "out");
  305. assertEntry(F, ignored, "out/foo");
  306. endWalk();
  307. }
  308. @Test
  309. public void testSlashMatchesDirectory() throws IOException {
  310. writeIgnoreFile(".gitignore", "out2/");
  311. writeTrashFile("out1/out1", "");
  312. writeTrashFile("out1/out2", "");
  313. writeTrashFile("out2/out1", "");
  314. writeTrashFile("out2/out2", "");
  315. beginWalk();
  316. assertEntry(F, tracked, ".gitignore");
  317. assertEntry(D, tracked, "out1");
  318. assertEntry(F, tracked, "out1/out1");
  319. assertEntry(F, tracked, "out1/out2");
  320. assertEntry(D, ignored, "out2");
  321. assertEntry(F, ignored, "out2/out1");
  322. assertEntry(F, ignored, "out2/out2");
  323. endWalk();
  324. }
  325. @Test
  326. public void testWildcardWithSlashMatchesDirectory() throws IOException {
  327. writeIgnoreFile(".gitignore", "out2*/");
  328. writeTrashFile("out1/out1.txt", "");
  329. writeTrashFile("out1/out2", "");
  330. writeTrashFile("out1/out2.txt", "");
  331. writeTrashFile("out1/out2x/a", "");
  332. writeTrashFile("out2/out1.txt", "");
  333. writeTrashFile("out2/out2.txt", "");
  334. writeTrashFile("out2x/out1.txt", "");
  335. writeTrashFile("out2x/out2.txt", "");
  336. beginWalk();
  337. assertEntry(F, tracked, ".gitignore");
  338. assertEntry(D, tracked, "out1");
  339. assertEntry(F, tracked, "out1/out1.txt");
  340. assertEntry(F, tracked, "out1/out2");
  341. assertEntry(F, tracked, "out1/out2.txt");
  342. assertEntry(D, ignored, "out1/out2x");
  343. assertEntry(F, ignored, "out1/out2x/a");
  344. assertEntry(D, ignored, "out2");
  345. assertEntry(F, ignored, "out2/out1.txt");
  346. assertEntry(F, ignored, "out2/out2.txt");
  347. assertEntry(D, ignored, "out2x");
  348. assertEntry(F, ignored, "out2x/out1.txt");
  349. assertEntry(F, ignored, "out2x/out2.txt");
  350. endWalk();
  351. }
  352. @Test
  353. public void testWithSlashDoesNotMatchInSubDirectory() throws IOException {
  354. writeIgnoreFile(".gitignore", "a/b");
  355. writeTrashFile("a/a", "");
  356. writeTrashFile("a/b", "");
  357. writeTrashFile("src/a/a", "");
  358. writeTrashFile("src/a/b", "");
  359. beginWalk();
  360. assertEntry(F, tracked, ".gitignore");
  361. assertEntry(D, tracked, "a");
  362. assertEntry(F, tracked, "a/a");
  363. assertEntry(F, ignored, "a/b");
  364. assertEntry(D, tracked, "src");
  365. assertEntry(D, tracked, "src/a");
  366. assertEntry(F, tracked, "src/a/a");
  367. assertEntry(F, tracked, "src/a/b");
  368. endWalk();
  369. }
  370. @Test
  371. public void testNoPatterns() throws IOException {
  372. writeIgnoreFile(".gitignore", "", " ", "# comment", "/");
  373. writeTrashFile("a/a", "");
  374. beginWalk();
  375. assertEntry(F, tracked, ".gitignore");
  376. assertEntry(D, tracked, "a");
  377. assertEntry(F, tracked, "a/a");
  378. endWalk();
  379. }
  380. @Test
  381. public void testLeadingSpaces() throws IOException {
  382. writeTrashFile(" a/ a", "");
  383. writeTrashFile(" a/ a", "");
  384. writeTrashFile(" a/a", "");
  385. writeTrashFile(" a/ a", "");
  386. writeTrashFile(" a/ a", "");
  387. writeTrashFile(" a/a", "");
  388. writeIgnoreFile(".gitignore", " a", " a");
  389. writeTrashFile("a/ a", "");
  390. writeTrashFile("a/ a", "");
  391. writeTrashFile("a/a", "");
  392. beginWalk();
  393. assertEntry(D, ignored, " a");
  394. assertEntry(F, ignored, " a/ a");
  395. assertEntry(F, ignored, " a/ a");
  396. assertEntry(F, ignored, " a/a");
  397. assertEntry(D, ignored, " a");
  398. assertEntry(F, ignored, " a/ a");
  399. assertEntry(F, ignored, " a/ a");
  400. assertEntry(F, ignored, " a/a");
  401. assertEntry(F, tracked, ".gitignore");
  402. assertEntry(D, tracked, "a");
  403. assertEntry(F, ignored, "a/ a");
  404. assertEntry(F, ignored, "a/ a");
  405. assertEntry(F, tracked, "a/a");
  406. endWalk();
  407. }
  408. @Test
  409. public void testTrailingSpaces() throws IOException {
  410. // Windows can't create files with trailing spaces
  411. // If this assumption fails the test is halted and ignored.
  412. org.junit.Assume.assumeFalse(SystemReader.getInstance().isWindows());
  413. writeTrashFile("a /a", "");
  414. writeTrashFile("a /a ", "");
  415. writeTrashFile("a /a ", "");
  416. writeTrashFile("a /a", "");
  417. writeTrashFile("a /a ", "");
  418. writeTrashFile("a /a ", "");
  419. writeTrashFile("a/a", "");
  420. writeTrashFile("a/a ", "");
  421. writeTrashFile("a/a ", "");
  422. writeIgnoreFile(".gitignore", "a\\ ", "a \\ ");
  423. beginWalk();
  424. assertEntry(F, tracked, ".gitignore");
  425. assertEntry(D, ignored, "a ");
  426. assertEntry(F, ignored, "a /a");
  427. assertEntry(F, ignored, "a /a ");
  428. assertEntry(F, ignored, "a /a ");
  429. assertEntry(D, ignored, "a ");
  430. assertEntry(F, ignored, "a /a");
  431. assertEntry(F, ignored, "a /a ");
  432. assertEntry(F, ignored, "a /a ");
  433. assertEntry(D, tracked, "a");
  434. assertEntry(F, tracked, "a/a");
  435. assertEntry(F, ignored, "a/a ");
  436. assertEntry(F, ignored, "a/a ");
  437. endWalk();
  438. }
  439. @Test
  440. public void testToString() throws Exception {
  441. assertEquals(Arrays.asList("").toString(), new IgnoreNode().toString());
  442. assertEquals(Arrays.asList("hello").toString(),
  443. new IgnoreNode(Arrays.asList(new FastIgnoreRule("hello")))
  444. .toString());
  445. }
  446. private void beginWalk() {
  447. walk = new TreeWalk(db);
  448. walk.addTree(new FileTreeIterator(db));
  449. }
  450. private void endWalk() throws IOException {
  451. assertFalse("Not all files tested", walk.next());
  452. }
  453. private void assertEntry(FileMode type, boolean entryIgnored,
  454. String pathName) throws IOException {
  455. assertTrue("walk has entry", walk.next());
  456. assertEquals(pathName, walk.getPathString());
  457. assertEquals(type, walk.getFileMode(0));
  458. WorkingTreeIterator itr = walk.getTree(0, WorkingTreeIterator.class);
  459. assertNotNull("has tree", itr);
  460. assertEquals("is ignored", entryIgnored, itr.isEntryIgnored());
  461. if (D.equals(type))
  462. walk.enterSubtree();
  463. }
  464. private void writeIgnoreFile(String name, String... rules)
  465. throws IOException {
  466. StringBuilder data = new StringBuilder();
  467. for (String line : rules)
  468. data.append(line + "\n");
  469. writeTrashFile(name, data.toString());
  470. }
  471. private InputStream writeToString(String... rules) throws IOException {
  472. StringBuilder data = new StringBuilder();
  473. for (String line : rules) {
  474. data.append(line + "\n");
  475. }
  476. return new ByteArrayInputStream(data.toString().getBytes("UTF-8"));
  477. }
  478. }