/** * Returns an icon for the specified file. * * @param file file reference * @return icon */ public static Icon file(final IOFile file) { if (file == null) return UNKNOWN; // fallback code for displaying icons final String path = file.path(); final MediaType type = MediaType.get(path); if (type.isXML()) return XML; if (type.isXQuery()) return XQUERY; if (path.contains(IO.BASEXSUFFIX)) return BASEX; // only works with standard dpi (https://bugs.openjdk.java.net/browse/JDK-6817929) if (Prop.WIN && !GUIConstants.large()) { // retrieve system icons (only supported on Windows) final int p = path.lastIndexOf(path, '.'); final String suffix = p == -1 ? null : path.substring(p + 1); Icon icon = null; if (suffix != null) icon = FILES.get(suffix); if (icon == null) { icon = FS.getSystemIcon(file.file()); if (suffix != null) FILES.put(suffix, icon); } return icon; } // default icon chooser return type.isText() ? TEXT : UNKNOWN; }
/** * Tests writing of request content when @src is set. * * @throws IOException I/O Exception */ @Test public void writeFromResource() throws IOException { // Create a file form which will be read final IOFile file = new IOFile(Prop.TMP, Util.className(FnHttpTest.class)); file.write(token("test")); // Request final HttpRequest req = new HttpRequest(); req.payloadAttrs.put("src", file.url()); req.payloadAttrs.put("method", "binary"); // HTTP connection final FakeHttpConnection fakeConn = new FakeHttpConnection(new URL("http://www.test.com")); HttpClient.setRequestContent(fakeConn.getOutputStream(), req); // Delete file file.delete(); assertEquals(fakeConn.out.toString(Strings.UTF8), "test"); }