I don’t think that’s quite what you want to do.
getResource would load a file from a classpath or jar… not from a
variable. If you want to pull a file in as a stream you want something
else.
You’d get the classloader from an instantiated class, or pull the system
class loader. (You probably wouldn’t create one)
I.e. if you want to pull a file from the same package as your
JsonObjectParser class:
<cfset obj = createobject(“java”,
“your.JsonObjectParser”).init(jsonFactory) />
<cfset stream = obj.getClass().getResourceAsStream(“variables.json”) />
would load your/variables.json from the same location as JsonObjectParser.
More likely you want something like
<cfset stream =
createobject(“java”,“java.io.FileInputStream”).init(ExpandPath(“./variables.json”))
/>
-GOn Tue, Nov 29, 2016 at 2:50 AM, AJ Mercer <@AJ_Mercer> wrote:
in CFML, how can I get to getResourceAsStream()?
cl = createObject(“java”, “java.lang.Class”);
dump(cl);
cl = createObject(“java”, “java.lang.ClassLoader”);
dump(cl);
both output
java.io.InputStream getResourceAsStream(java.lang.String)
But when I do this I get an error
myR = cl.getResourceAsStream(variables.json);
dump(myR);
[image: Inline images 1]
[image: Inline images 2]
I need to load a file and kept it’s mime type
from Java class that I am passing file to
JsonObjectParser parser = new JsonObjectParser(jsonFactory);
GenericJson fileContents = parser.parseAndClose(
credentialStream, OAuth2Utils.UTF_8, GenericJson.class);
String fileType = (String) fileContents.get(“type”);
if (fileType == null) {
throw new IOException(“Error reading credentials from stream,
‘type’ field not specified.”);
}
–
AJ Mercer
<webonix:net strength=“Industrial” /> http://webonix.net | <webonix:org
community=“Open” /> http://webonix.org
http://twitter.com/webonix
–
Get 10% off of the regular price for this years CFCamp in Munich, Germany
(Oct. 20th & 21st) with the Lucee discount code Lucee@cfcamp. 189€
instead of 210€. Visit https://ti.to/cfcamp/cfcamp-
2016/discount/Lucee@cfcamp
You received this message because you are subscribed to the Google Groups
“Lucee” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/lucee/CAPURtC3UKDzik64uHy%2BRZYku2mjPW7Ajm%2B3GS82kUj_
98mqAqA%40mail.gmail.com
https://groups.google.com/d/msgid/lucee/CAPURtC3UKDzik64uHy%2BRZYku2mjPW7Ajm%2B3GS82kUj_98mqAqA%40mail.gmail.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

