MCPcopy Create free account
hub / github.com/apache/pig / fetchResource

Method fetchResource

src/org/apache/pig/impl/io/FileLocalizer.java:857–887  ·  view source on GitHub ↗

Ensures that the passed resource is available from the local file system, fetching it to a temporary directory. @throws ResourceNotFoundException

(String name)

Source from the content-addressed store, hash-verified

855 * @throws ResourceNotFoundException
856 */
857 public static FetchFileRet fetchResource(String name) throws IOException, ResourceNotFoundException {
858 FetchFileRet localFileRet = null;
859 InputStream resourceStream = PigContext.getClassLoader().getResourceAsStream(name);
860 if (resourceStream != null) {
861 File dest = new File(localTempDir, name);
862 dest.getParentFile().mkdirs();
863 dest.deleteOnExit();
864
865 OutputStream outputStream = null;
866 try {
867 outputStream = new BufferedOutputStream(new FileOutputStream(dest));
868 byte[] buffer = new byte[1024];
869 int len;
870 while ((len=resourceStream.read(buffer)) > 0) {
871 outputStream.write(buffer,0,len);
872 }
873 } finally {
874 resourceStream.close();
875 if (outputStream != null) {
876 outputStream.close();
877 }
878 }
879 localFileRet = new FetchFileRet(dest,false);
880 }
881 else
882 {
883 throw new ResourceNotFoundException(name);
884 }
885
886 return localFileRet;
887 }
888}

Callers 1

getMacroFileMethod · 0.95

Calls 5

getClassLoaderMethod · 0.95
mkdirsMethod · 0.80
closeMethod · 0.65
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected