How can I use OSHI to get a file's HWDiskStore? [duplicate] - oshi

I am using OSHI https://github.com/oshi/oshi to monitor the hardware.
There is a method
HWDiskStore[] getDisks();
https://github.com/oshi/oshi/blob/master/oshi-core/src/main/java/oshi/hardware/Disks.java
to get the list of all hard drives on the machine.
Is it possible to get HWDiskStore for a particular path like
FileStore getFileStore(Path path)
https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#getFileStore-java.nio.file.Path-
If no, what is a reliable way to match a HWDiskStore with a given path, e.g. use disk name or serial number, etc.?

The DiskStore is a hardware object (e.g., hard drive, SSD, etc.) which is part of the machinery, while the FileStore is a software object associated with the Operating System / File System.
OSHI's HWDiskStore objects have a getPartitions() method, which returns an array of HWPartition objects. These objects have a getMountPoint() method which should be a String corresponding to the OSFileStore mount point.
OSHI's OSFileStore objects correspond to the Java FileStore objects and have a getMount() method which should directly match the HWPartition mount point.
This demo class gives an example of how this information can be correlated.

Related

Who is ultimately responsible for setting URLResourceValues for URLs on disk?

Who is ultimately responsible for setting URLResourceValues for URL objects that go on disk? When I create a file on disk, creationDate and contentAccessDate are automatically set for me, but contentAccessDate doesn't appear to ever change on its own when I access their paths. I can update the values manually with setResourceValues() but am I supposed to? And why does creationDate have a setter? Shouldn't that value strictly be set by the system?
Quick links:
https://developer.apple.com/documentation/foundation/urlresourcevalues
https://developer.apple.com/documentation/foundation/urlresourcevalues/1779762-contentaccessdate

What are ways to store complex dynamic objects locally (iOS, swift)?

I have iOS app that takes data from the server as json and then serializes them into objects of different types. Types can be complicated, can contain subtypes, can inherit, so there is no any limitations. Another thing that makes everything even more complicated is some of types are stored as AnyObject? and only in run time they are being serialized into real types accordingly to the specific rules. Something like that:
class A {
var typeName: String?
var b: AnyObject?
}
Then when it's serialized it can be done something like that:
if let someClass = NSClassFromString(typeName) as? SomeGenericType.Type{
b = someClass.init()
}
Also querying should be done on all the data. Currently I'm trying to store all of them locally, then load into memory and query there from the code. I'm using User defaults, but they have some limitations, also I needed to provide custom coding to make it work, and each time when I add a new field it turned out that I missed something in coding and nothing works. So it's pain.
Ideally I would just do some magic command and all the objects are sent to local storage no matter how complicated they are. The same to extract them from this storage. Also, user change data so I can't just store primary Json. And I don't want to covert objects back to Jason as for it's pain too.
Any suggestions?
If you want to use sqlite then You can store whole object in one row! I means you can create table with 2 columns one is id and second is your dataobject(it's data type should be blob). Then convert your whole object into data. Then store in sqlite table and retrieve it as data then convert it to object when want to use. By this way your object will remains in same format as you asked
Firebase while meant for online synching and storage can also cache everything locally in case you are offline and perform query's against the local cache. It uses JSON.
CouchDB also has a mobile version for iOS.
Both of those are over kill if your dataset is small; you can just store it as a text file and read the JSON back in. See performance characteristics here. The graph is for a 7MB file so if you are significantly less than that your load time may be minimal.
NSKeyedArchiver.archivedData(withRootObject:) is great for storing custom objects as Data objects. The only thing you need to do to be able to use this is to make your custom objects conform to NSCoding. A great example can be found here:
Save custom objects into NSUserDefaults
Once you have the Data version of the object, it can easily be stored in UserDefaults, as a property in CoreData, or even in the app's keychain entries. Depending on your use case, sensitivity of data, and how much data you intend to store, you might want to use any number of storage methods. NSKeyedArchiver.archivedData(withRootObject:) allows you to pretty much use any of them.

when to use globalIdField

As far as I can tell, relay relies on nodeDefitions for queries when variables are being changed.
It'd appear that all objects with an id field should be a valid node. However, if I have data like this:
type User {
id: globalIdField('User'),
name: String,
folders: [ Folder ]
}
type Folder {
id: ???,
...
}
The data is stored in a document based solution, and the Folder objects are nested in the User object. But Folder objects are given an id so that some other objects could reference the Folder objects under the context of a User.
If Folder implements the nodeInterface, and uses globalIdField, then I need to figure out a way to fetch the Folder object from a globalId, meaning that I might have to scan through all the Users to find it, have a data map that'd allow me to find the object, or normalize the data so that Folders are in their own table.
If it doesn't implement the nodeInterface, and just uses Strings as id field, what happens when I try to mutate some fields on the Folder object?
It's often useful for these objects to have ids, even if there's no real id directly in your database. For example, if you want to write a mutation to rename a folder, it'd be great to have a global ID to reference this folder. Relay also uses them internally when the UI requests some additional data on a node that's not loaded yet.
One way to generate a global ID for the folder could be to take a prefix and add the user id and a way to identify the folder within the user, for example:
var folderID = ['folder', userID, folderID].join(':');
Whenever you want to resolve this id on your server, you split at the :, see that you want to load a folder by looking at the first part and then go via user to the right folder.

CoreData and the "Allows External Storage" option

I'm doing a tutorial on CoreData and they talked about the "Allows External Storage" option. The documentation says "When enabled, Core Data heuristically decides on a per-value basis if it should save the data directly in the database or store a URI to a separate file which it manages for you. You cannot query based on the contents of a binary data property if you use this option." I understand the first part but I don't understand what they mean by "You cannot query based on the contents of a binary data property if you use this option". I feel this is important stuff, but I can't understand it. "You cannot query based on the contents of a binary data", what does that mean? I don't if it's my bad english or something but I can't figure it out.
The tutorial is "Core Data by Tutorials" from the Ray Wenderlich's tutorial book series. I highly recommend!
image the NSData you store is jpeg data with an exif header.
if you store the data inside the DB, you can use a predicate matching said exif data: e.g. something like (pseudo) "jpgedData CONTAINS author: dominik"
if you store it as a separate file, that query wouldn't work as the data isn't really inside the database
[note that this was explanatory pseudo code and I can't really think of a practical / useful example]
All that means is that if you enable that option for a property, you can't use that property in an NSPredicate when fetching objects. A fetch request is a query, and when you use a predicate you're fetching objects based on whether they match the predicate. That doesn't work if external storage is allowed for the property.
Ok I think I got it. Basically you can't use the image's raw meta data to look for a specific image, because you don't have access to the raw data. You only have access to the URI. Sounds logical and fair to me, since you could just extract the meta data, and store it in your CoreData model before saving the image as a transformable (if need be).

Vector /List work with Storage in lwuit?

I try to save vector or default list on storage. All work fine until i close the application and open again. When i call to Storage , the storage don't find this vector.
Do have Problem to use this objects with Storage in lwuit?
The writeObject method accepts a second parameter as a Object. It returns true or false. If you object is suitable in the Storage you will get true. Try to put this vector and see what returns this method.
Last week I try to put a custom object and it doesn't work. I think hashtables can be in Storage, but ListModels doesn't.
Storage API

Resources