Getting Java Interface.class from Lucee

How do i get BasicFileAttributes.class, if doing this from CFML
(Determine file creation date in Java - Stack Overflow)?

Path file = …;

BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);

System.out.println("creationTime: " + attr.creationTime());

System.out.println("lastAccessTime: " + attr.lastAccessTime());

System.out.println("lastModifiedTime: " + attr.lastModifiedTime());

BTW, this:

basicFileAttributes = createObject(“java”, “java.nio.file.attribute.BasicFileAttributes”);

writeDump(basicFileAttributes.class);

…throws this (on the dump line):

No matching Constructor for java.nio.file.attribute.BasicFileAttributes() found

Thanks,

Jamie

I forgot to mention that my first guess:

basicFileAttributes = createObject(“java”,
“java.nio.file.attribute.BasicFileAttributes”).getClass();

…failed with:

No matching Method for getClass() found for
java.nio.file.attribute.BasicFileAttributesOn Thursday, August 20, 2015 at 4:15:09 PM UTC-4, Jamie Jackson wrote:

How do i get BasicFileAttributes.class, if doing this from CFML (
Determine file creation date in Java - Stack Overflow)?

Path file = …;

BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);

System.out.println("creationTime: " + attr.creationTime());

System.out.println("lastAccessTime: " + attr.lastAccessTime());

System.out.println("lastModifiedTime: " + attr.lastModifiedTime());

BTW, this:

basicFileAttributes = createObject(“java”, “java.nio.file.attribute.BasicFileAttributes”);

writeDump(basicFileAttributes.class);

…throws this (on the dump line):

No matching Constructor for java.nio.file.attribute.BasicFileAttributes() found

Thanks,

Jamie

CFML and Java do not play together well with what you are trying to do. Here is a way to read creationTime using java.nio.file.Files:

paths = createObject("java", "java.nio.file.Paths" ); path = paths.get( "/Users/rmunn/lucee", [] ); //options = createObject("java", "java.nio.file.LinkOption" ); files = createObject("java", "java.nio.file.Files" ).readAttributes( path, "*", [] );

You can use [ options.NOFOLLOW_LINKS ] as the third argument of the last command if you want to ignore links…

Robert> On Aug 20, 2015, at 1:21 PM, Jamie Jackson <@Jamie_Jackson> wrote:

I forgot to mention that my first guess:

basicFileAttributes = createObject(“java”, “java.nio.file.attribute.BasicFileAttributes”).getClass();

…failed with:

No matching Method for getClass() found for java.nio.file.attribute.BasicFileAttributes

On Thursday, August 20, 2015 at 4:15:09 PM UTC-4, Jamie Jackson wrote:
How do i get BasicFileAttributes.class, if doing this from CFML (Determine file creation date in Java - Stack Overflow http://stackoverflow.com/a/2724009/)?

Path file = …;
BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);

System.out.println("creationTime: " + attr.creationTime());
System.out.println("lastAccessTime: " + attr.lastAccessTime());
System.out.println("lastModifiedTime: " + attr.lastModifiedTime());
BTW, this:
basicFileAttributes = createObject(“java”, “java.nio.file.attribute.BasicFileAttributes”);
writeDump(basicFileAttributes.class);
…throws this (on the dump line):
No matching Constructor for java.nio.file.attribute.BasicFileAttributes() found
Thanks,
Jamie


See Lucee at CFCamp Oct 22 & 23 2015 @ Munich Airport, Germany - Get your ticket NOW - http://www.cfcamp.org/ http://www.cfcamp.org/

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 mailto:lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com mailto:lucee@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/c7b902f8-fabe-4ae1-9de6-27ea286cf011%40googlegroups.com https://groups.google.com/d/msgid/lucee/c7b902f8-fabe-4ae1-9de6-27ea286cf011%40googlegroups.com?utm_medium=email&utm_source=footer.
For more options, visit https://groups.google.com/d/optout https://groups.google.com/d/optout.

So if all we need is read-only access to the attributes, we could condense
your code into:

Cheers Robert, that’s not really the (/my) point here though. The aim was
to have working CFML code that demonstrated the incompat between Lucee and
ColdFusion. TBH, I didn’t even look @ what the code did, I just translated
the example Java code into CFML, and checked that it worked (ie: ran, doing
whateverTF it was doing… something to do with files… I seriously didn’t
bother to read it, which is quite odd now that I think about it) on
ColdFusion, and did not on Lucee.

It’s always good to be shown “better code” though I guess (I didn’t look @
your code either though. Someone else no-doubt will!)On Friday, 21 August 2015 21:00:02 UTC+1, Robert Munn wrote:

CFML and Java do not play together well with what you are trying to do.

I think it’s more that Lucee and Java don’t play nicely here.

This is a perfectly working version of the Java code in that StackOverflow
link http://stackoverflow.com/a/14455760/894061, in CFML:

dir = expandPath(“./”);

paths = createObject(“java”, “java.nio.file.Paths”);
p = paths.get(dir, []);

files = createObject(“java”, “java.nio.file.Files”);

linkOption = createObject(“java”, “java.nio.file.LinkOption”);
linkOptions = linkOption.values();

basicFileAttributeView = createObject(“java”,
“java.nio.file.attribute.BasicFileAttributeView”);
basicFileAttributeViewClass=basicFileAttributeView.getClass();

view = files.getFileAttributeView(p, basicFileAttributeViewClass,
linkOptions).readAttributes();

writeOutput(“#view.creationTime()# is the same as #view.lastModifiedTime()#”
);

I hasten to add my Java is fairly pedestrian, and this is just the result
of taking the code from StackOverflow and doing all the extra stuff CFML
needs to do the same thing. It might not be the best way to go about things.

On ColdFusion this outputs:

2015-08-21T07:52:50.951374Z is the same as 2015-08-21T07:53:03.644183Z

(that’s obviously nonsense, but it’s what the code is supposed to do)

On Lucee it errors cos one cannot call getClass() as indicated earlier.

:-/On Friday, 21 August 2015 08:30:17 UTC+1, Robert Munn wrote:

The reason to use/return the BasicFileAttributeView is if you want to use the setTimes() method to change the file time attributes. Otherwise,using the Files.readAttributes() method I used returns a read-only Map of the same file attributes available in the View class.

So if all we need is read-only access to the attributes, we could condense your code into:

paths = createObject("java", "java.nio.file.Paths" );
path = paths.get( expandPath("./"), [] );
options = createObject("java", "java.nio.file.LinkOption" );
attrs = createObject("java", "java.nio.file.Files" ).readAttributes( path, "*", options.values() );

writeOutput("#attrs.creationTime.toString()# is the same as #attrs.lastModifiedTime.toString()#");> On Aug 21, 2015, at 1:11 AM, Adam Cameron <@Adam_Cameron> wrote:

I hasten to add my Java is fairly pedestrian, and this is just the result of taking the code from StackOverflow and doing all the extra stuff CFML needs to do the same thing. It might not be the best way to go about things.

On ColdFusion this outputs:

2015-08-21T07:52:50.951374Z is the same as 2015-08-21T07:53:03.644183Z

(that’s obviously nonsense, but it’s what the code is supposed to do)

On Lucee it errors cos one cannot call getClass() as indicated earlier.

:-/


See Lucee at CFCamp Oct 22 & 23 2015 @ Munich Airport, Germany - Get your ticket NOW - http://www.cfcamp.org/ http://www.cfcamp.org/

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 mailto:lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com mailto:lucee@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/58cb0334-c0dc-47d2-9bbf-99214ac54733%40googlegroups.com https://groups.google.com/d/msgid/lucee/58cb0334-c0dc-47d2-9bbf-99214ac54733%40googlegroups.com?utm_medium=email&utm_source=footer.
For more options, visit https://groups.google.com/d/optout https://groups.google.com/d/optout.

Micha has put up a fix for the issue raised relating to this so hopefully
that’ll help sort this out!
[LDEV-502] - Lucee Friday, 21 August 2015 09:11:59 UTC+1, Adam Cameron wrote:

On Friday, 21 August 2015 08:30:17 UTC+1, Robert Munn wrote:

CFML and Java do not play together well with what you are trying to do.

I think it’s more that Lucee and Java don’t play nicely here.

This is a perfectly working version of the Java code in that StackOverflow
link http://stackoverflow.com/a/14455760/894061, in CFML:

dir = expandPath(“./”);

paths = createObject(“java”, “java.nio.file.Paths”);
p = paths.get(dir, []);

files = createObject(“java”, “java.nio.file.Files”);

linkOption = createObject(“java”, “java.nio.file.LinkOption”);
linkOptions = linkOption.values();

basicFileAttributeView = createObject(“java”,
“java.nio.file.attribute.BasicFileAttributeView”);
basicFileAttributeViewClass=basicFileAttributeView.getClass();

view = files.getFileAttributeView(p, basicFileAttributeViewClass,
linkOptions).readAttributes();

writeOutput(“#view.creationTime()# is the same as
#view.lastModifiedTime()#”);

I hasten to add my Java is fairly pedestrian, and this is just the result
of taking the code from StackOverflow and doing all the extra stuff CFML
needs to do the same thing. It might not be the best way to go about things.

On ColdFusion this outputs:

2015-08-21T07:52:50.951374Z is the same as 2015-08-21T07:53:03.644183Z

(that’s obviously nonsense, but it’s what the code is supposed to do)

On Lucee it errors cos one cannot call getClass() as indicated earlier.

:-/