Title: Creating DataHandle
Open Graph Title: Creating DataHandle
X Title: Creating DataHandle
Description: Most popular situations, when we need DataHandle, are processing files and byte arrays, implemented in the classes FileHandle and BytesHandle. Unfortunately, the only correct way to create the necessary objects is using SciHava context t...
Open Graph Description: Most popular situations, when we need DataHandle, are processing files and byte arrays, implemented in the classes FileHandle and BytesHandle. Unfortunately, the only correct way to create the nece...
X Description: Most popular situations, when we need DataHandle, are processing files and byte arrays, implemented in the classes FileHandle and BytesHandle. Unfortunately, the only correct way to create the nece...
Opengraph URL: https://github.com/scijava/scijava-common/issues/468
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Creating DataHandle\u003cLocation\u003e from FileLocation and BytesLocation ","articleBody":"Most popular situations, when we need DataHandle, are processing files and byte arrays, implemented in the classes FileHandle and BytesHandle. Unfortunately, the only correct way to create the necessary objects is using SciHava context technique:\r\n\r\n`context.getService(DataHandleService.class).create(location)`\r\n\r\nBut initializing context sub-system requires time and special code. I would be very desirable to avoid Context class in these very simple situation.\r\n\r\nI've found necessary solution as a pair of simple functions:\r\n\r\n```\r\n @SuppressWarnings(\"rawtypes, unchecked\")\r\n public static DataHandle\u003cLocation\u003e getFileHandle(FileLocation fileLocation) {\r\n Objects.requireNonNull(fileLocation, \"Null fileLocation\");\r\n FileHandle fileHandle = new FileHandle();\r\n fileHandle.set(fileLocation);\r\n return (DataHandle) fileHandle;\r\n }\r\n\r\n @SuppressWarnings(\"rawtypes, unchecked\")\r\n public static DataHandle\u003cLocation\u003e getBytesHandle(BytesLocation bytesLocation) {\r\n Objects.requireNonNull(bytesLocation, \"Null bytesLocation\");\r\n BytesHandle bytesHandle = new BytesHandle();\r\n bytesHandle.set(bytesLocation);\r\n return (DataHandle) bytesHandle;\r\n }\r\n\r\n```\r\nCould you provide such convenient methods inside FileLocation/ByteLocation classes?\r\n\r\nBesides, you see that it turned out to be necessary to use @SupressWarning to make necessary `DataHandle\u003cLocation\u003e`. Maybe you should rework generics in your module to provide ability to return `DataHandle\u003cLocation\u003e` without compiler warnings? Or, at least, please make the methods getFileHandle/getBytesHandle with @SupressWarning a part of your own classes, to avoid your users to write unsafe code.\r\n\r\nIt is a duplicate of the issue https://github.com/scifio/scifio/issues/508 - it seems here is more suitable place. So you may close that issue in SCIFIO project.\r\n","author":{"url":"https://github.com/Daniel-Alievsky","@type":"Person","name":"Daniel-Alievsky"},"datePublished":"2023-08-06T12:13:54.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/468/scijava-common/issues/468"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:0699b356-8328-18db-70a6-0ccad1411154 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A2F0:2C4B08:F88A9B:153ACAA:6969F506 |
| html-safe-nonce | 86f9d5edf8f814f315891720ce3c71e0b856085b2c09c44bf322b958ec3e2198 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMkYwOjJDNEIwODpGODhBOUI6MTUzQUNBQTo2OTY5RjUwNiIsInZpc2l0b3JfaWQiOiI3ODU2NzU3NTM1OTA3NDg0MjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 52ea956c963e5701fed000793d2f8f158b28297cad6e11c7a10997b1b35f8a6f |
| hovercard-subject-tag | issue:1838185467 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/scijava/scijava-common/468/issue_layout |
| twitter:image | https://opengraph.githubassets.com/35b40cb88181b395bee8e978f5743609b319adf429cd7b30dc222000f3aa4936/scijava/scijava-common/issues/468 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/35b40cb88181b395bee8e978f5743609b319adf429cd7b30dc222000f3aa4936/scijava/scijava-common/issues/468 |
| og:image:alt | Most popular situations, when we need DataHandle, are processing files and byte arrays, implemented in the classes FileHandle and BytesHandle. Unfortunately, the only correct way to create the nece... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Daniel-Alievsky |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7b32f1c7c4549428ee399213e8345494fc55b5637195d3fc5f493657579235e8 |
| turbo-cache-control | no-preview |
| go-import | github.com/scijava/scijava-common git https://github.com/scijava/scijava-common.git |
| octolytics-dimension-user_id | 1262770 |
| octolytics-dimension-user_login | scijava |
| octolytics-dimension-repository_id | 3594497 |
| octolytics-dimension-repository_nwo | scijava/scijava-common |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3594497 |
| octolytics-dimension-repository_network_root_nwo | scijava/scijava-common |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | bdde15ad1b403e23b08bbd89b53fbe6bdf688cad |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width