Loading a file from filesystem in SPRING - spring

I have been strugling with this for a long while.
I am using an outer API and I need to pass file's path directly. I cannot modify it.
I looks like: functionmethod(String path);
So i cannot use Resource because I need to pass just path.
Is it possible in SPRING?

Maybe you could use:
(new File("")).getAbsolutePath() that gives you the current path (application).
or (I think this one will fit better for you)
getResource("fileName").getFile()

Related

Is there a Go implementation of fs.ReadDir for Google Cloud Storage?

I am creating a web application in Go.
I have modified my working code so that it can read and write files on both a local filesystem and a bucket of Google Cloud Storage based on a flag.
Basically I included a small package in the middle, and I implemented my-own-pkg.readFile or my-own-pkg.WriteFile and so on...
I have replaced all calls in my code where I read or save files from the local filesystem with calls to my methods.
Finally these methods include a simple switch case that runs the standard code to read/write locally or the code to read/wrote from/to a gcp bucket.
My current problem
In some parts I need to perform a ReadDir to get the list of DirEntries and then cycle though them. I do not want to change my code except for replacing os.readDir with my-own-pkg.ReadDir.
So far I understand that there is not a native function in the gcp module. So I suppose (but here I need your help because I am just guessing) that I would need an implementation of fs.FS for the gcp. It being a new feature of go 1.6 I guess it's too early to find one.
So I am trying to create simply a my-own-pkg.ReadDir(folderpath) function that does the following:
case "local": { }
case "gcp": {
<Use gcp code sample to list objects in my bucket with Query.Prefix = folderpath and
Query.Delimiter="/"
Then create a slice of my-own-pkg.DirEntry (because fs.DkrEntry is just an interface and so it needs to be implemented... :-( ) and return them.
In order to do so I need to implement also the interface fs.DirEntry (which requires the implementation of interface for FileInfo and maybe something else...)
Question 1) is this the right path to follow to solve my issue or is there a better way?
Question 2) (only) if so, does the gcp method that lists object with a prefix and a delimiter return just files? I can't see a method that returns also the list of prefixes found
(If I have prefix/file1.txt and prefix/a/file2.txt I would like to get both "file1.txt" and "a" as files and prefixes...)
I hope I was enough clear... This time I can't include code because it's incomplete... But in case it helps I can paste what I can.
NOTE: by the way go 1.6 allowed me to solve elegantly a similar issue when dealing with assets either embedded or on the filesystem thanks to the existing implementation of fs.FS and the related ReadDirFS. So good if I could follow the same route 🙂
By the way I am going on studying and experimenting so in case I am successful I will contribute as well :-)
I think your abstraction layer is good but you need to know something on Cloud Storage: The directory doesn't exist.
In fact, all the object are put at the root of the bucket / and the fully qualified name of the object is /path/to/object.file. You can filter on a prefix, that return all the object (i.e. file because directory doesn't exist) with the same path prefix.
It's not a full answer to your question but I'm sure that you can think and redesign the rest of your code with this particularity in mind.

How do I assign a name to a v8::Object so that scripts can access it?

I'm currently trying to add scripting functionality to my C++ application by using v8. The goal is to process some data in buffers with JS and then return the result. I think I can generate an ArrayBuffer by using New with an appropriate BackingStore. The result would be a Local. I would now like to run scripts via v8::Script::Compile and v8::Script::Run. What would be the name of the ArrayBuffer - or how can I assign it a name so that it's accessible in the script? Do I need to make it a Globalif I need to run multiple scripts on the same ArrayBuffer?
If you want scripts to be able to access, say, my_array_buffer, then you'll have to install the ArrayBuffer as a property on the global object. See https://v8.dev/docs/embed for an introduction to embedding V8, and the additional examples linked from there. In short, it'll boil down to something like:
global_object->Set(context,
v8::String::NewFromUtf8(isolate, "my_array_buffer"),
array_buffer);
You don't need to store the ArrayBuffer in a Global for this to work.

How to change generated files output path in Docpad?

I want to do something like what docpad-plugin-dateurls does but in the context of static site generation.
I need, for example, to map the file /src/documents/posts/2013-09-10-post-title.html to the url http://localhost:9778/posts/2013/09/10/post-title.html
Which would be the best approach to acomplish this requirement?
You would do something like this: https://github.com/Greduan/eduantech.docpad/blob/d5e97638331ab24730d3331b9fbcc30cf1d46dcc/docpad.coffee#L45-L49
You would modify it for your needs but it does what you need I think. :)
I finally implemented this by setting the outPath of each document in the renderBefore event.
See here: https://github.com/gschuager/blog/blob/7451fbcb829ad93154d24b281c7e8e30d3a0edac/docpad.js#L83

distinguish use cases in NSAutosaveElsewhereOperation

I try to add AutoSave support to the Core Data File Wrapper example
Now if i have a new/untitled document writeSafelyToURL is called with the NSAutosaveElsewhereOperation type.
The bad thing is, I get this type in both typical use cases
- new file: which store a complete new document by creating the file wrapper and the persistent store file
- save diff: where the file wrapper already exists and only an update is required.
Does somebody else already handled this topic or did somebody already migrated this?
The original sample use the originalStoreURL to distinguish those two use cases, which solution worked best for you?
Thanks

Using DiskVolumeInfo (Cluster Failover API)

I found the DiskVolumeInfo property -- I'd like to use it to get some disk information in a clustered setup.
http://msdn.microsoft.com/en-us/library/windows/desktop/bb309235(v=vs.85).aspx
The problem is I have no idea what technology is required to get this data. This doesn't resemble the standard C/C++/C#/VB format of function/method reference.
Question: How do I get the DiskVolumeInfo data?
Ideally I could write the binary output directly to a file, say data.bin.
Any ideas would be helpful, thanks.
The process for getting object properties is described here.
Looks like you need to call the ClusterResourceControl function with a handle to the physical disk resource and the CLUSCTL_RESOURCE_GET_PRIVATE_PROPERTIES control code. You can then use ResUtilFindBinaryProperty to extract the DiskVolumeInfo property from the property list returned.
For anyone still interested:
As given here CLUSCTL_RESOURCE_STORAGE_GET_DISK_INFO_EX is a better way to do this.

Resources