private JarInputStream getEmbeddedJarInputStream(final JarURLConnection embeddedJarUrlConnection) throws IOException { final JarInputStream embeddedJarInputStream; try { final InputStream inputStream = embeddedJarUrlConnection.getInputStream(); embeddedJarInputStream = new JarInputStream(inputStream); } catch (IOException ex) { // TODO: Notify this to reporters as far as possible. System.err.println("Failed to load entry in embedded JAR: " + embeddedJarUrlConnection.toString()); ex.printStackTrace(); throw ex; } return embeddedJarInputStream; }
new JarInputStream(embeddedJarUrlConnection.getInputStream());
private static URL lookMavenMetadataFileUrlFromJar(File artifactFile, String mavenMetadataFileName) { String mavenMetadataFilePath = MULE_ARTIFACT_PATH_INSIDE_JAR + "/" + mavenMetadataFileName; URL possibleUrl; try { possibleUrl = getUrlWithinJar(artifactFile, mavenMetadataFilePath); /* * A specific implementation of JarURLConnection is required to read jar content because not all implementations * support ways to disable connection caching. Disabling connection caching is necessary to avoid file descriptor leaks. */ JarURLConnection jarConnection = new sun.net.www.protocol.jar.JarURLConnection(possibleUrl, new sun.net.www.protocol.jar.Handler()); jarConnection.setUseCaches(false); try (InputStream ignored = jarConnection.getInputStream()) { return possibleUrl; } catch (Exception e) { List<URL> jarMavenUrls = getUrlsWithinJar(artifactFile, META_INF + "/" + "maven"); Optional<URL> mavenMetadataUrl = jarMavenUrls.stream().filter(url -> url.toString().endsWith(mavenMetadataFileName)).findAny(); if (!mavenMetadataUrl.isPresent()) { throw new ArtifactDescriptorCreateException(format("The identifier '%s' requires the file '%s' within the artifact(error found while reading artifact '%s')", artifactFile.getName(), mavenMetadataFileName, artifactFile.getAbsolutePath())); } return mavenMetadataUrl.get(); } } catch (IOException e) { throw new MuleRuntimeException(e); } }
public static InputStream getInputStreamForURL(URL url) throws IOException { JarURLConnection conn = (JarURLConnection) url.openConnection(); return conn.getInputStream(); }
private static InputStream processURL(URL url) throws IOException{ String sUrl = url.toString(); if (sUrl.indexOf(".jar") != -1) { sUrl = "jar:" + url + "!/" + "package.properties"; URL jarUrl = new URL(sUrl); JarURLConnection jarConnection = (JarURLConnection)jarUrl.openConnection(); return jarConnection.getInputStream(); } return url.openStream(); }
public InputStream getInputStream() throws IOException { if(url == null) throw new IOException("Resource doesn't exist: " + uri); JarURLConnection con = getConnection(); return con.getInputStream(); }
public JarRepresentation(final String uri) { super(FileURIDereferencer.findMediaType(uri)); JarURLConnection jc; try { jc = (JarURLConnection) (new URL(uri).openConnection()); inputStream = jc.getInputStream(); } catch (IOException e) { throw new IllegalArgumentException(e); } }
@Override public InputStream getInputStream() throws IOException { InputStream in = jarURLConnection.getInputStream(); return xDecryptor.decrypt(xKey, in); }
public InputStream getInputStream() throws IOException { if(url == null) throw new IOException("Resource doesn't exist: " + uri); JarURLConnection con = getConnection(); return con.getInputStream(); }
public JarRepresentation(final String uri) { super(FileURIDereferencer.findMediaType(uri)); JarURLConnection jc; try { jc = (JarURLConnection) (new URL(uri).openConnection()); inputStream = jc.getInputStream(); } catch (IOException e) { throw new IllegalArgumentException(e); } }
@Override public InputStream getInputStream() throws IOException { InputStream in = jarURLConnection.getInputStream(); return xDecryptor.decrypt(xKey, in); }
@Override public InputStream getInputStream() throws IOException { InputStream in = jarURLConnection.getInputStream(); return xDecryptor.decrypt(xKey, in); }
try { conn = (JarURLConnection) new URL(jarEntry).openConnection(); r = new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8); StringBuilder sb = new StringBuilder(); int data = r.read();
/** * * @param jarUrl * @return */ protected byte[] _getData(URL jarUrl) { if (jarUrl != null) { try { JarURLConnection jar = (JarURLConnection) jarUrl.openConnection(); BufferedInputStream bis = new BufferedInputStream(jar.getInputStream()); ByteBuffer b = ByteBuffer.allocate(jar.getContentLength()).order(ByteOrder.nativeOrder()); byte[] r = new byte[512]; int rB = 0; while ((rB = bis.read(r)) != -1) { b.put(r, 0, rB); } bis.close(); return b.array(); } catch (IOException ex) { if (isDebugEnabled()) { ex.printStackTrace(); } } } return null; }
/** * Loads the content of a file within a jar into a byte array. * * @param jarFile the jar file * @return the content of the file as byte array or empty if the file does not exists within the jar file. * @throws IOException if there was a problem reading from the jar file. */ public static Optional<byte[]> loadFileContentFrom(URL jarFile) throws IOException { /* * A specific implementation of JarURLConnection is required to read jar content because not all implementations * support ways to disable connection caching. Disabling connection caching is necessary to avoid file descriptor leaks. */ JarURLConnection jarConnection = new sun.net.www.protocol.jar.JarURLConnection(jarFile, new sun.net.www.protocol.jar.Handler()); jarConnection.setUseCaches(false); try (InputStream inputStream = jarConnection.getInputStream()) { byte[] byteArray = toByteArray(inputStream); return of(byteArray); } catch (FileNotFoundException e) { return empty(); } }
public static ContentData resourceData(URL url) { String protocol = url.getProtocol(); if ("file".equals(protocol)) { try { File file = new File(url.toURI()); if (!file.isDirectory()) { return new FileContentData(file, file.length(), new Date((file.lastModified() / 1000) * 1000)); } } catch (URISyntaxException e) { throw new UnreachableException(e); } } else if ("jar".equals(protocol)) { try { JarURLConnection connection = (JarURLConnection) url.openConnection(); if (connection != null && !isJarDirectory(connection)) { return new StreamContentData(connection.getInputStream(), connectionContentLength(connection), connectionLastModified(connection)); } } catch (IOException e) { throw new FalteringEnvironmentException(e); } } return null; }
/** * Loads the content of a file within a jar into a byte array. * * @param jarFile the jar file * @param filePath the path to the file within the jar file * @return the content of the file as byte array or empty if the file does not exists within the jar file. * @throws IOException if there was a problem reading from the jar file. */ public static Optional<byte[]> loadFileContentFrom(File jarFile, String filePath) throws IOException { URL jsonDescriptorUrl = getUrlWithinJar(jarFile, filePath); /* * A specific implementation of JarURLConnection is required to read jar content because not all implementations * support ways to disable connection caching. Disabling connection caching is necessary to avoid file descriptor leaks. */ JarURLConnection jarConnection = new sun.net.www.protocol.jar.JarURLConnection(jsonDescriptorUrl, new sun.net.www.protocol.jar.Handler()); jarConnection.setUseCaches(false); try (InputStream inputStream = jarConnection.getInputStream()) { byte[] byteArray = toByteArray(inputStream); return of(byteArray); } catch (FileNotFoundException e) { return empty(); } }
internalPath = entry.getName(); internalDate = new Date(entry.getLastModifiedTime().toMillis()); ChunkedInput<ByteBuf> content = new ChunkedStream(jarConnection.getInputStream()); return writeResponse(ctx, request, content, length); } catch (IOException e) {
if (source.getDocumentIRI().getNamespace().startsWith("jar:")) { try { return streamFromJar(source.getDocumentIRI()).getInputStream(); } catch (IOException e) { source.setIRIResolutionFailed(true);
if (source.getDocumentIRI().getNamespace().startsWith("jar:")) { try { return streamFromJar(source.getDocumentIRI()).getInputStream(); } catch (IOException e) { source.setIRIResolutionFailed(true);