Explore all File Utils open source software, libraries, packages, source code, cloud functions and APIs.

Popular New Releases in File Utils

hosts

Release 3.9.65

croc

v9.5.3

filebrowser

v2.21.1

chokidar

3.5.2

finder

v6.0.3

Popular Libraries in File Utils

hosts

by StevenBlack doticonpythondoticon

star image 20509 doticonMIT

🔒 Consolidating and extending hosts files from several well-curated sources. Optionally pick extensions for porn, social media, and other categories.

croc

by schollz doticongodoticon

star image 18933 doticonMIT

Easily and securely send things from one computer to another :crocodile: :package:

filebrowser

by filebrowser doticongodoticon

star image 15215 doticonApache-2.0

📂 Web File Browser

chokidar

by paulmillr doticonjavascriptdoticon

star image 8625 doticonMIT

Minimal and efficient cross-platform file watching library

node-fs-extra

by jprichardson doticonjavascriptdoticon

star image 8386 doticonMIT

Node.js: extra methods for the fs object like copy(), remove(), mkdirs()

finder

by symfony doticonphpdoticon

star image 7911 doticonMIT

The Finder component finds files and directories via an intuitive fluent interface.

webuploader

by fex-team doticonjavascriptdoticon

star image 7502 doticonBSD-3-Clause

It's a new file uploader solution!

pifs

by philipl doticoncdoticon

star image 5273 doticonGPL-3.0

πfs - the data-free filesystem!

Aria

by AriaLyy doticonjavadoticon

star image 4621 doticonApache-2.0

下载可以很简单

Trending New libraries in File Utils

webdav-aliyundriver

by zxbu doticonjavadoticon

star image 2282 doticon

阿里云盘(https://www.aliyundrive.com/) 的webdav协议开源实现

hosts

by ineo6 doticontypescriptdoticon

star image 1439 doticonMIT

GitHub最新hosts。解决GitHub图片无法显示,加速GitHub网页浏览。

distribyted

by distribyted doticongodoticon

star image 865 doticonGPL-3.0

Torrent client with HTTP, fuse, and WebDAV interfaces. Start exploring your torrent files right away, even zip, rar, or 7zip archive contents!

CleanMyWechat

by blackboxo doticonpythondoticon

star image 861 doticon

自动删除 PC 端微信缓存数据,包括从所有聊天中自动下载的大量文件、视频、图片等数据内容,解放你的空间。

transfer

by Mikubill doticongodoticon

star image 554 doticonMIT

🍭 集合多个API的大文件传输工具.

lfs

by Canop doticonrustdoticon

star image 432 doticonMIT

A linux utility to get information on filesystems, like df but better

wormhole-gui

by Jacalz doticongodoticon

star image 431 doticonGPL-3.0

Cross-platform application for easy encrypted sharing of files, folders, and text between devices.

cap-std

by bytecodealliance doticonrustdoticon

star image 392 doticonNOASSERTION

Capability-oriented version of the Rust standard library

cursedfs

by NieDzejkob doticonshelldoticon

star image 371 doticonWTFPL

Make a disk image formatted with both ext2 and FAT at once

Top Authors in File Utils

1

sindresorhus

21 Libraries

star icon3713

2

jonschlinkert

20 Libraries

star icon340

3

martinmoene

15 Libraries

star icon1629

4

mafintosh

11 Libraries

star icon427

5

npm

10 Libraries

star icon374

6

vasi

8 Libraries

star icon257

7

vi

7 Libraries

star icon52

8

shinnn

7 Libraries

star icon41

9

ferhatgec

7 Libraries

star icon37

10

absfs

6 Libraries

star icon19

1

21 Libraries

star icon3713

2

20 Libraries

star icon340

3

15 Libraries

star icon1629

4

11 Libraries

star icon427

5

10 Libraries

star icon374

6

8 Libraries

star icon257

7

7 Libraries

star icon52

8

7 Libraries

star icon41

9

7 Libraries

star icon37

10

6 Libraries

star icon19

Trending Kits in File Utils

No Trending Kits are available at this moment for File Utils

Trending Discussions on File Utils

Android 11: Send e-mail with automatically attached file

Update events in calendar after change in variable - Fullcalendar

ssl certificate issue for jgit in javafx app image versus javafx app runtime

I have doubts about double pointer as parameters for a swap function

QUESTION

Android 11: Send e-mail with automatically attached file

Asked 2021-Jun-02 at 13:39

I want open and email app with already generated text, subject, recipient and attached file, it works with android sdk version 29 (android 10) and lower. However starting Android 11 there are restriction to writing file in external or internal storages, and there is also another restriction that is not allowed to attach file automatically from app file directory. Previously I was copying from app storage to internal or external storage to attach file, any solutions?

done android:requestLegacyExternalStorage="true"

1public static void sendMail(Context context) throws IOException {
2        Context appContext = context.getApplicationContext();
3
4        File logFile = FileUtils.createFile(context.getFilesDir().getAbsolutePath(), "testFile.txt", "Test");
5
6        File logsDirectory = new File(FileUtils.getStorageDirectory(appContext), "files");
7        logsDirectory.mkdirs();
8
9        File destFile = new File(logsDirectory, "log.txt");
10
11        InputStream in = new FileInputStream(logFile);
12        boolean copied = FileUtils.copyToFile(in, destFile);
13
14        Uri logPath = Uri.fromFile(destFile);
15
16        Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
17        emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
18        emailIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
19        // set the type to 'email'
20        emailIntent.setData(Uri.parse("mailto:"));
21        String[] to = {"support@test.com"};
22        String subject = "Test log";
23        String body =
24                "Hello";
25        emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
26        emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
27        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
28        // the attachment
29        emailIntent.putExtra(Intent.EXTRA_STREAM, logPath);
30
31        context.startActivity(Intent.createChooser(emailIntent, "Send email..."));
32    } 
33
1public static void sendMail(Context context) throws IOException {
2        Context appContext = context.getApplicationContext();
3
4        File logFile = FileUtils.createFile(context.getFilesDir().getAbsolutePath(), "testFile.txt", "Test");
5
6        File logsDirectory = new File(FileUtils.getStorageDirectory(appContext), "files");
7        logsDirectory.mkdirs();
8
9        File destFile = new File(logsDirectory, "log.txt");
10
11        InputStream in = new FileInputStream(logFile);
12        boolean copied = FileUtils.copyToFile(in, destFile);
13
14        Uri logPath = Uri.fromFile(destFile);
15
16        Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
17        emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
18        emailIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
19        // set the type to 'email'
20        emailIntent.setData(Uri.parse("mailto:"));
21        String[] to = {"support@test.com"};
22        String subject = "Test log";
23        String body =
24                "Hello";
25        emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
26        emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
27        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
28        // the attachment
29        emailIntent.putExtra(Intent.EXTRA_STREAM, logPath);
30
31        context.startActivity(Intent.createChooser(emailIntent, "Send email..."));
32    } 
33public class FileUtils {
34    
35        public static String getExtensionFromFileName(String fileName) {
36        if (fileName == null) return null;
37
38        String extension = null;
39        int i = fileName.lastIndexOf('.');
40        if (i > 0) {
41            extension = fileName.substring(i + 1);
42        }
43        return extension;
44    }
45
46    /**
47     * Copy data from a source stream to destFile. Return true if succeed, return false if failed.
48     */
49    public static boolean copyToFile(InputStream inputStream, File destFile) {
50        if (inputStream == null || destFile == null) return false;
51        try {
52            try (OutputStream out = new FileOutputStream(destFile)) {
53                byte[] buffer = new byte[4096];
54                int bytesRead;
55                while ((bytesRead = inputStream.read(buffer)) >= 0) {
56                    out.write(buffer, 0, bytesRead);
57                }
58            }
59            return true;
60        } catch (IOException e) {
61            Log.e("[File Utils]", "copyToFile exception: " + e);
62
63        }
64        return false;
65    }
66
67
68    public static String getStorageDirectory(Context mContext) {
69        String storageDir =
70                Environment.getExternalStorageDirectory().getAbsolutePath()
71                        + "/"
72                        + mContext.getString(R.string.app_name);
73        File file = new File(storageDir);
74        mContext.getExternalMediaDirs();
75
76        if (!file.isDirectory() || !file.exists()) {
77
78
79        }
80        return storageDir;
81    }
82
83    public static File createFile(String directory ,String fileName, String textToAttach)
84    {
85        File logFile = new File(directory  + "/" + fileName);
86        if (!logFile.exists())
87        {
88            try
89            {
90                logFile.createNewFile();
91            }
92            catch (IOException e)
93            {
94                // TODO Auto-generated catch block
95                e.printStackTrace();
96            }
97        }
98        try
99        {
100            //BufferedWriter for performance, true to set append to file flag
101            BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true));
102            buf.append(textToAttach);
103            buf.newLine();
104            buf.close();
105        }
106        catch (IOException e)
107        {
108            // TODO Auto-generated catch block
109            e.printStackTrace();
110        }
111        return logFile;
112    }
113}
114

ANSWER

Answered 2021-Jun-02 at 13:39

I have done using FileProvider and selector, this is for multiple files

1public static void sendMail(Context context) throws IOException {
2        Context appContext = context.getApplicationContext();
3
4        File logFile = FileUtils.createFile(context.getFilesDir().getAbsolutePath(), "testFile.txt", "Test");
5
6        File logsDirectory = new File(FileUtils.getStorageDirectory(appContext), "files");
7        logsDirectory.mkdirs();
8
9        File destFile = new File(logsDirectory, "log.txt");
10
11        InputStream in = new FileInputStream(logFile);
12        boolean copied = FileUtils.copyToFile(in, destFile);
13
14        Uri logPath = Uri.fromFile(destFile);
15
16        Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
17        emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
18        emailIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
19        // set the type to 'email'
20        emailIntent.setData(Uri.parse("mailto:"));
21        String[] to = {"support@test.com"};
22        String subject = "Test log";
23        String body =
24                "Hello";
25        emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
26        emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
27        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
28        // the attachment
29        emailIntent.putExtra(Intent.EXTRA_STREAM, logPath);
30
31        context.startActivity(Intent.createChooser(emailIntent, "Send email..."));
32    } 
33public class FileUtils {
34    
35        public static String getExtensionFromFileName(String fileName) {
36        if (fileName == null) return null;
37
38        String extension = null;
39        int i = fileName.lastIndexOf('.');
40        if (i > 0) {
41            extension = fileName.substring(i + 1);
42        }
43        return extension;
44    }
45
46    /**
47     * Copy data from a source stream to destFile. Return true if succeed, return false if failed.
48     */
49    public static boolean copyToFile(InputStream inputStream, File destFile) {
50        if (inputStream == null || destFile == null) return false;
51        try {
52            try (OutputStream out = new FileOutputStream(destFile)) {
53                byte[] buffer = new byte[4096];
54                int bytesRead;
55                while ((bytesRead = inputStream.read(buffer)) >= 0) {
56                    out.write(buffer, 0, bytesRead);
57                }
58            }
59            return true;
60        } catch (IOException e) {
61            Log.e("[File Utils]", "copyToFile exception: " + e);
62
63        }
64        return false;
65    }
66
67
68    public static String getStorageDirectory(Context mContext) {
69        String storageDir =
70                Environment.getExternalStorageDirectory().getAbsolutePath()
71                        + "/"
72                        + mContext.getString(R.string.app_name);
73        File file = new File(storageDir);
74        mContext.getExternalMediaDirs();
75
76        if (!file.isDirectory() || !file.exists()) {
77
78
79        }
80        return storageDir;
81    }
82
83    public static File createFile(String directory ,String fileName, String textToAttach)
84    {
85        File logFile = new File(directory  + "/" + fileName);
86        if (!logFile.exists())
87        {
88            try
89            {
90                logFile.createNewFile();
91            }
92            catch (IOException e)
93            {
94                // TODO Auto-generated catch block
95                e.printStackTrace();
96            }
97        }
98        try
99        {
100            //BufferedWriter for performance, true to set append to file flag
101            BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true));
102            buf.append(textToAttach);
103            buf.newLine();
104            buf.close();
105        }
106        catch (IOException e)
107        {
108            // TODO Auto-generated catch block
109            e.printStackTrace();
110        }
111        return logFile;
112    }
113}
114public static void sendMail(Context context) {
115        Context appContext = context.getApplicationContext();
116        final String authority = appContext.getPackageName() + ".FileProvider";
117        String[] to = {"test@test.com"};
118        String subject = "subject";
119        String body = "body";
120        
121        ArrayList<File> logFiles = getLogFile(context);
122
123        if (logFiles.size() == 0) {
124            Toast.makeText(
125                            context,
126                            context.getString(R.string.toast_send_failed_no_file_found),
127                            Toast.LENGTH_LONG)
128                    .show();
129            return;
130        }
131        // has to be an ArrayList
132
133        ArrayList<Uri> logPaths = new ArrayList<>();
134        for (File file : logFiles) {
135            if (file.exists()) {
136                logPaths.add(FileProvider.getUriForFile(appContext, authority, file));
137            }
138        }
139
140        Intent emailSelectorIntent = new Intent(Intent.ACTION_SENDTO);
141        emailSelectorIntent.setDataAndType(Uri.parse("mailto:"), "plain/text");
142
143        final Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
144        // emailIntent.setType("plain/text");
145        emailIntent.addFlags(
146                Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
147
148        emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
149        emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
150        emailIntent.putExtra(Intent.EXTRA_TEXT, body);
151        emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, logPaths);
152        emailIntent.setSelector(emailSelectorIntent);
153
154        context.startActivity(Intent.createChooser(emailIntent, "Send Logs"));
155    }
156

Source https://stackoverflow.com/questions/67006600

QUESTION

Update events in calendar after change in variable - Fullcalendar

Asked 2021-Mar-25 at 08:11

Using Fullcalendar with Vue.js, I'm passing the initial events from a variable, but I need that after this variable is updated, the events were updated in the calendar also. The documentation seems to be clear about that: enter image description here

But I've tried this and nothing happens, the events keeps as the first renderization.
Also I've looked in many SO related answers about this topic but most of them are applied with JQuery which is not my case.
I can't figure out how to aply this in a correct way.
Thanks in advance for your attention...

My code to create the calendar:

1<FullCalendar :options="calendarOptions" ref="fullCalendar"/>
2
3data() {
4    return {
5      calendarOptions: {
6        firstDay: new Date().getDay(),
7        plugins: [timeGridPlugin, interactionPlugin],
8        headerToolbar: {
9          left: '',
10          center: 'title',
11          right: 'prev,next'
12        },
13        initialView: 'timeGridWeek',
14        slotMinTime: "09:00:00",
15        slotMaxTime: "20:00:00",
16        height: "1070px",
17        expandRows: true ,
18        dayHeaderFormat: { weekday: 'narrow', day: 'numeric' },
19        events: displayEvents
20      },
21      ...
22

The function that update the variable:

1<FullCalendar :options="calendarOptions" ref="fullCalendar"/>
2
3data() {
4    return {
5      calendarOptions: {
6        firstDay: new Date().getDay(),
7        plugins: [timeGridPlugin, interactionPlugin],
8        headerToolbar: {
9          left: '',
10          center: 'title',
11          right: 'prev,next'
12        },
13        initialView: 'timeGridWeek',
14        slotMinTime: "09:00:00",
15        slotMaxTime: "20:00:00",
16        height: "1070px",
17        expandRows: true ,
18        dayHeaderFormat: { weekday: 'narrow', day: 'numeric' },
19        events: displayEvents
20      },
21      ...
22getEvents() {
23    this.displayEvents = [
24        {
25                id: 1,
26                title: "TEST1",
27                start: "2021-03-29 09:00:00",
28                end: "2021-03-29 11:00:00",
29                backgroundColor: "#FF5733"
30        },
31        {
32                id: 2,
33                title: "TEST2",
34                start: "2021-03-29 10:00:00",
35                end: "2021-03-29 11:05:00",
36                backgroundColor: "#0053B8"
37        },
38    ]
39    let calendarApi = this.$refs.fullCalendar.getApi()
40    calendarApi('refetchEvents')
41    this.$refs.fullCalendar('refetchEvents')
42}
43

(displayEvents came from another javascript file utils.js, and after execute the function it is modified)

UPDATE: I found that I was calling the .fullCalendar('refetchEvents') method in an incorrect way. Now I'm calling it as it:

1<FullCalendar :options="calendarOptions" ref="fullCalendar"/>
2
3data() {
4    return {
5      calendarOptions: {
6        firstDay: new Date().getDay(),
7        plugins: [timeGridPlugin, interactionPlugin],
8        headerToolbar: {
9          left: '',
10          center: 'title',
11          right: 'prev,next'
12        },
13        initialView: 'timeGridWeek',
14        slotMinTime: "09:00:00",
15        slotMaxTime: "20:00:00",
16        height: "1070px",
17        expandRows: true ,
18        dayHeaderFormat: { weekday: 'narrow', day: 'numeric' },
19        events: displayEvents
20      },
21      ...
22getEvents() {
23    this.displayEvents = [
24        {
25                id: 1,
26                title: "TEST1",
27                start: "2021-03-29 09:00:00",
28                end: "2021-03-29 11:00:00",
29                backgroundColor: "#FF5733"
30        },
31        {
32                id: 2,
33                title: "TEST2",
34                start: "2021-03-29 10:00:00",
35                end: "2021-03-29 11:05:00",
36                backgroundColor: "#0053B8"
37        },
38    ]
39    let calendarApi = this.$refs.fullCalendar.getApi()
40    calendarApi('refetchEvents')
41    this.$refs.fullCalendar('refetchEvents')
42}
43let calendarApi = this.$refs.fullCalendar.getApi()
44calendarApi.refetchEvents()
45

But still the changes aren't reflected in the calendar after this.

ANSWER

Answered 2021-Mar-25 at 07:27

Your events don't update because you're using a static event source - that array was copied to fullCalendar when it was initialised. Updates to it have no effect on the calendar because fullCalendar is using a different, older copy of the array.

And fullCalendar has no way to refetch anything because you didn't give it a source to fetch from. If you want re-fetching to work then you need to provide a dynamic event source. There are two techniques you can use to do that, both described in detail in the documentation:

  1. Events as a JSON feed - where you simply specify a URL which will return JSON event data directly. fullCalendar will call this URL whenever the date changes - or whenever you call refetchEvents - and pass the current start and end dates of the calendar as query parameters, so the server can return a list of events correctly filtered by date.

  2. Events as a function - where you provide a callback function which fullCalendar will call whenever the date changes - or whenever you call refetchEvents - and passes the current start and end date as parameters to the function. The function can then do whatever you want in order to fetch events - e.g. make a custom AJAX call, or call another function or whatever. When the events are ready you pass them back to fullCalendar using the "successCallback" function supplied as a parameter to the main callback. There's an example in the documentation.

Source https://stackoverflow.com/questions/66792785

QUESTION

ssl certificate issue for jgit in javafx app image versus javafx app runtime

Asked 2020-Nov-12 at 15:37

I have developed a simple JavaFX app using jgit, that is allowing users to play with git.

When the app was started from the IntelliJ idea, I was able to clone the GitHub repo using my jgit implementation of the "git clone" command without any issues. But as soon as I created an image from my app and started the app from the image, I am getting an SSL certificate issue:

Exception:org.eclipse.jgit.api.errors.TransportException: Secure connection to https://my-github-repo.git could not be established because of SSL problems.

I am trying to understand why I am getting the SSL certificate issue only when I am running the app from the image. Can somebody explain that? I understand that I can disable SSL verification (there are some questions answered on that topic), but I want to know why it is working from IDE and not from the created image...

here is my simplified git clone implementation for http:

1try { 
2
3            CloneCommand command = Git.cloneRepository();
4
5            command.setCredentialsProvider(new UsernamePasswordCredentialsProvider(httpUsername, httpPassword));
6
7            // run the clone command
8            command.setURI(repositoryUrl);
9            command.setDirectory(dirFramework);
10            git = command.call();
11
12} catch (Exception e) {
13    LOG.error("Error occurred during task: Git clone: " + e);
14}
15

For creating the image I am using the "org.beryx.runtime" plugin with the Gradle task "runtime".

Here is the build.gradle content:

1try { 
2
3            CloneCommand command = Git.cloneRepository();
4
5            command.setCredentialsProvider(new UsernamePasswordCredentialsProvider(httpUsername, httpPassword));
6
7            // run the clone command
8            command.setURI(repositoryUrl);
9            command.setDirectory(dirFramework);
10            git = command.call();
11
12} catch (Exception e) {
13    LOG.error("Error occurred during task: Git clone: " + e);
14}
15plugins {
16    id 'java'
17    id 'application'
18    id 'org.openjfx.javafxplugin' version '0.0.8'
19    id 'org.beryx.runtime' version '1.11.4'
20}
21
22group 'org.sovap'
23version '1.0-SNAPSHOT'
24
25sourceCompatibility = 11
26targetCompatibility = 11
27
28repositories {
29    mavenCentral()
30}
31
32dependencies {
33
34    // xml stuff
35    compile 'jakarta.xml.bind:jakarta.xml.bind-api:2.3.3'
36    compile 'org.glassfish.jaxb:jaxb-runtime:2.3.2'
37    compile 'jakarta.activation:jakarta.activation-api:1.2.2'
38
39    // logger
40    compile 'org.apache.logging.log4j:log4j-core:2.13.3'
41    compile 'org.slf4j:slf4j-api:1.7.30'
42    compile 'org.slf4j:slf4j-simple:1.7.30'
43
44    // cucumber
45    compile 'io.cucumber:gherkin:15.0.2'
46
47    // jgit
48    compile 'org.eclipse.jgit:org.eclipse.jgit:5.9.0.202009080501-r'
49    compile 'org.eclipse.jgit:org.eclipse.jgit.archive:5.9.0.202009080501-r'
50    compile 'org.eclipse.jgit:org.eclipse.jgit.ssh.jsch:5.9.0.202009080501-r'
51
52    // file utils
53    compile 'commons-io:commons-io:2.7'
54
55    //controlsfx
56    compile 'org.controlsfx:controlsfx:11.0.2'
57
58}
59
60javafx {
61    version = "15"
62    modules = ['javafx.controls', 'javafx.fxml', 'javafx.web', "javafx.graphics"]
63}
64
65application {
66    mainClassName = 'org.sovap.taman.Launcher'
67    applicationName = 'taman'
68}
69
70runtime {
71    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
72    imageDir = file("$buildDir/taman")
73}
74

Edit 1:

How the image is created? - image is created with the plugin 'org.beryx.runtime' version '1.11.4', with Gradle task called 'runtime'. At the end of the build.gradle content you can see some specific configuration for runtime task.

Also, it is possible to include modules there as described here: https://badass-runtime-plugin.beryx.org/releases/latest/

I have tested the config with modules you are mentioning for runtime task in build.gradle (also one by one):

1try { 
2
3            CloneCommand command = Git.cloneRepository();
4
5            command.setCredentialsProvider(new UsernamePasswordCredentialsProvider(httpUsername, httpPassword));
6
7            // run the clone command
8            command.setURI(repositoryUrl);
9            command.setDirectory(dirFramework);
10            git = command.call();
11
12} catch (Exception e) {
13    LOG.error("Error occurred during task: Git clone: " + e);
14}
15plugins {
16    id 'java'
17    id 'application'
18    id 'org.openjfx.javafxplugin' version '0.0.8'
19    id 'org.beryx.runtime' version '1.11.4'
20}
21
22group 'org.sovap'
23version '1.0-SNAPSHOT'
24
25sourceCompatibility = 11
26targetCompatibility = 11
27
28repositories {
29    mavenCentral()
30}
31
32dependencies {
33
34    // xml stuff
35    compile 'jakarta.xml.bind:jakarta.xml.bind-api:2.3.3'
36    compile 'org.glassfish.jaxb:jaxb-runtime:2.3.2'
37    compile 'jakarta.activation:jakarta.activation-api:1.2.2'
38
39    // logger
40    compile 'org.apache.logging.log4j:log4j-core:2.13.3'
41    compile 'org.slf4j:slf4j-api:1.7.30'
42    compile 'org.slf4j:slf4j-simple:1.7.30'
43
44    // cucumber
45    compile 'io.cucumber:gherkin:15.0.2'
46
47    // jgit
48    compile 'org.eclipse.jgit:org.eclipse.jgit:5.9.0.202009080501-r'
49    compile 'org.eclipse.jgit:org.eclipse.jgit.archive:5.9.0.202009080501-r'
50    compile 'org.eclipse.jgit:org.eclipse.jgit.ssh.jsch:5.9.0.202009080501-r'
51
52    // file utils
53    compile 'commons-io:commons-io:2.7'
54
55    //controlsfx
56    compile 'org.controlsfx:controlsfx:11.0.2'
57
58}
59
60javafx {
61    version = "15"
62    modules = ['javafx.controls', 'javafx.fxml', 'javafx.web', "javafx.graphics"]
63}
64
65application {
66    mainClassName = 'org.sovap.taman.Launcher'
67    applicationName = 'taman'
68}
69
70runtime {
71    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
72    imageDir = file("$buildDir/taman")
73}
74runtime {
75    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
76    imageDir = file("$buildDir/taman")
77    modules = ['jdk.crypto.cryptoki', 'jdk.crypto.ec', 'jdk.crypto.mscapi']
78}
79

But with that I am getting following exception when starting the app from image:

1try { 
2
3            CloneCommand command = Git.cloneRepository();
4
5            command.setCredentialsProvider(new UsernamePasswordCredentialsProvider(httpUsername, httpPassword));
6
7            // run the clone command
8            command.setURI(repositoryUrl);
9            command.setDirectory(dirFramework);
10            git = command.call();
11
12} catch (Exception e) {
13    LOG.error("Error occurred during task: Git clone: " + e);
14}
15plugins {
16    id 'java'
17    id 'application'
18    id 'org.openjfx.javafxplugin' version '0.0.8'
19    id 'org.beryx.runtime' version '1.11.4'
20}
21
22group 'org.sovap'
23version '1.0-SNAPSHOT'
24
25sourceCompatibility = 11
26targetCompatibility = 11
27
28repositories {
29    mavenCentral()
30}
31
32dependencies {
33
34    // xml stuff
35    compile 'jakarta.xml.bind:jakarta.xml.bind-api:2.3.3'
36    compile 'org.glassfish.jaxb:jaxb-runtime:2.3.2'
37    compile 'jakarta.activation:jakarta.activation-api:1.2.2'
38
39    // logger
40    compile 'org.apache.logging.log4j:log4j-core:2.13.3'
41    compile 'org.slf4j:slf4j-api:1.7.30'
42    compile 'org.slf4j:slf4j-simple:1.7.30'
43
44    // cucumber
45    compile 'io.cucumber:gherkin:15.0.2'
46
47    // jgit
48    compile 'org.eclipse.jgit:org.eclipse.jgit:5.9.0.202009080501-r'
49    compile 'org.eclipse.jgit:org.eclipse.jgit.archive:5.9.0.202009080501-r'
50    compile 'org.eclipse.jgit:org.eclipse.jgit.ssh.jsch:5.9.0.202009080501-r'
51
52    // file utils
53    compile 'commons-io:commons-io:2.7'
54
55    //controlsfx
56    compile 'org.controlsfx:controlsfx:11.0.2'
57
58}
59
60javafx {
61    version = "15"
62    modules = ['javafx.controls', 'javafx.fxml', 'javafx.web', "javafx.graphics"]
63}
64
65application {
66    mainClassName = 'org.sovap.taman.Launcher'
67    applicationName = 'taman'
68}
69
70runtime {
71    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
72    imageDir = file("$buildDir/taman")
73}
74runtime {
75    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
76    imageDir = file("$buildDir/taman")
77    modules = ['jdk.crypto.cryptoki', 'jdk.crypto.ec', 'jdk.crypto.mscapi']
78}
79Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/stream/XMLStreamException
80        at org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory.newConfigurationBuilder(ConfigurationBuilderFactory.java:38)
81        at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.<init>(PropertiesConfigurationBuilder.java:72)
82        at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:52)
83        at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:35)
84        at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:551)
85        at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:475)
86        at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:323)
87        at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:687)
88        at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:708)
89        at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
90        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
91        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
92        at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
93        at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:602)
94        at org.sovap.taman.App.<clinit>(App.java:15)
95        at org.sovap.taman.Launcher.main(Launcher.java:6)
96Caused by: java.lang.ClassNotFoundException: javax.xml.stream.XMLStreamException
97        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
98        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
99        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
100        ... 16 more
101

What version of Java 11 are you using? - java version "11.0.8" 2020-07-14 LTS Regarding the different versions of JDK for image and for IntelliJ IDEA environment - it should be using the same installation on my machine

I guess I need to add modules to the runtime task, but I do not know which ones and how to identify them... Any direction you can point me to?

Edit 2:

According to the accepted answer, I was missing modules in my runtime task configuration. Here is how I have figured which ones to add:

The plugin 'org.beryx.runtime' contains a task I used for suggesting modules for the runtime task (task: suggestModules) After running it I have created a list of modules with the following runtime config (included the ones from accepted answer):

1try { 
2
3            CloneCommand command = Git.cloneRepository();
4
5            command.setCredentialsProvider(new UsernamePasswordCredentialsProvider(httpUsername, httpPassword));
6
7            // run the clone command
8            command.setURI(repositoryUrl);
9            command.setDirectory(dirFramework);
10            git = command.call();
11
12} catch (Exception e) {
13    LOG.error("Error occurred during task: Git clone: " + e);
14}
15plugins {
16    id 'java'
17    id 'application'
18    id 'org.openjfx.javafxplugin' version '0.0.8'
19    id 'org.beryx.runtime' version '1.11.4'
20}
21
22group 'org.sovap'
23version '1.0-SNAPSHOT'
24
25sourceCompatibility = 11
26targetCompatibility = 11
27
28repositories {
29    mavenCentral()
30}
31
32dependencies {
33
34    // xml stuff
35    compile 'jakarta.xml.bind:jakarta.xml.bind-api:2.3.3'
36    compile 'org.glassfish.jaxb:jaxb-runtime:2.3.2'
37    compile 'jakarta.activation:jakarta.activation-api:1.2.2'
38
39    // logger
40    compile 'org.apache.logging.log4j:log4j-core:2.13.3'
41    compile 'org.slf4j:slf4j-api:1.7.30'
42    compile 'org.slf4j:slf4j-simple:1.7.30'
43
44    // cucumber
45    compile 'io.cucumber:gherkin:15.0.2'
46
47    // jgit
48    compile 'org.eclipse.jgit:org.eclipse.jgit:5.9.0.202009080501-r'
49    compile 'org.eclipse.jgit:org.eclipse.jgit.archive:5.9.0.202009080501-r'
50    compile 'org.eclipse.jgit:org.eclipse.jgit.ssh.jsch:5.9.0.202009080501-r'
51
52    // file utils
53    compile 'commons-io:commons-io:2.7'
54
55    //controlsfx
56    compile 'org.controlsfx:controlsfx:11.0.2'
57
58}
59
60javafx {
61    version = "15"
62    modules = ['javafx.controls', 'javafx.fxml', 'javafx.web', "javafx.graphics"]
63}
64
65application {
66    mainClassName = 'org.sovap.taman.Launcher'
67    applicationName = 'taman'
68}
69
70runtime {
71    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
72    imageDir = file("$buildDir/taman")
73}
74runtime {
75    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
76    imageDir = file("$buildDir/taman")
77    modules = ['jdk.crypto.cryptoki', 'jdk.crypto.ec', 'jdk.crypto.mscapi']
78}
79Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/stream/XMLStreamException
80        at org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory.newConfigurationBuilder(ConfigurationBuilderFactory.java:38)
81        at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.<init>(PropertiesConfigurationBuilder.java:72)
82        at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:52)
83        at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:35)
84        at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:551)
85        at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:475)
86        at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:323)
87        at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:687)
88        at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:708)
89        at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
90        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
91        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
92        at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
93        at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:602)
94        at org.sovap.taman.App.<clinit>(App.java:15)
95        at org.sovap.taman.Launcher.main(Launcher.java:6)
96Caused by: java.lang.ClassNotFoundException: javax.xml.stream.XMLStreamException
97        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
98        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
99        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
100        ... 16 more
101runtime {
102    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
103    imageDir = file("$buildDir/taman")
104    modules = [
105            'java.desktop',
106            'java.logging',
107            'java.xml',
108            'java.compiler',
109            'java.datatransfer',
110            'java.rmi',
111            'java.sql',
112            'java.naming',
113            'java.scripting',
114            'java.management',
115            'java.security.jgss',
116            'jdk.jfr',
117            'java.net.http',
118            'jdk.jsobject',
119            'jdk.xml.dom',
120            'jdk.unsupported',
121            'jdk.crypto.cryptoki',
122            'jdk.crypto.ec',
123            'jdk.crypto.mscapi']
124}
125

Now everything works as expected.

ANSWER

Answered 2020-Nov-12 at 15:37

The most likely situation is that you are missing a module in the JRE image related to crypto that is required to authenticate the SSL connection.

What jdk.crypto.* modules are in the final image? Perhaps if one of these is missing it will affect the ability to handle the SSL certificates?

  • jdk.crypto.cryptoki
  • jdk.crypto.ec
  • jdk.crypto.mscapi

Since some aspects of the security/crypto code are done via service providers, perhaps when you generate the JRE image you should pass the "--bind-services" option to "Link in service provider modules and their dependences"

You will need to share more details about how the image is created and what specific errors are reported. Try to include the full stack trace of any reported exceptions.

What version of Java 11 are you using? Could you be running into this: JDK 11 SSL Error on valid certificate (working in previous versions)

(It is unlikely if you are running with the same JDK version in the IDE and the packaged image, but thought I would mention it just in case it gives you a hint.)

Source https://stackoverflow.com/questions/64791882

QUESTION

I have doubts about double pointer as parameters for a swap function

Asked 2020-May-14 at 00:29

I hope you can help me! I added this function to my array.c to shuffle the array elements and it works with static Item *a; static int dim; in my array.c.

1static Item *a; 
2static int dim = 3;
3
4a=malloc( dim * sizeof(Item);
5
6void random_array() {
7                                  int i , j;
8                                  Item t;
9                                  for (i = dim - 1;i > 0; i--)
10                                  {
11                                      j = rand() % (i + 1);
12                                      t = a[i];
13                                      a[i] = a[j];
14                                      a[j] = t;
15                                     //swap(a[i], a[j]);
16                                  }
17                           }
18

item.h

1static Item *a; 
2static int dim = 3;
3
4a=malloc( dim * sizeof(Item);
5
6void random_array() {
7                                  int i , j;
8                                  Item t;
9                                  for (i = dim - 1;i > 0; i--)
10                                  {
11                                      j = rand() % (i + 1);
12                                      t = a[i];
13                                      a[i] = a[j];
14                                      a[j] = t;
15                                     //swap(a[i], a[j]);
16                                  }
17                           }
18typedef void *Item;
19

item-int.c

1static Item *a; 
2static int dim = 3;
3
4a=malloc( dim * sizeof(Item);
5
6void random_array() {
7                                  int i , j;
8                                  Item t;
9                                  for (i = dim - 1;i > 0; i--)
10                                  {
11                                      j = rand() % (i + 1);
12                                      t = a[i];
13                                      a[i] = a[j];
14                                      a[j] = t;
15                                     //swap(a[i], a[j]);
16                                  }
17                           }
18typedef void *Item;
19#include <stdio.h>
20#include <stdlib.h>
21#include "item.h"
22
23Item inputItem(){
24    int *p;
25    p=malloc(sizeof(int));
26    scanf("%d",p);
27    return p;
28}
29
30void outputItem(Item item){
31    int *p;
32    p=item;
33    printf("%d ",*p);
34}
35
36int cmpItem(Item item1,Item item2){
37    int *p1,*p2;
38    p1 = item1;
39    p2 = item2;
40    return *p1 - *p2;
41
42}
43

So I tried with a function swap (a[i], a[j]) from the file utils.c but it doesn't work.

1static Item *a; 
2static int dim = 3;
3
4a=malloc( dim * sizeof(Item);
5
6void random_array() {
7                                  int i , j;
8                                  Item t;
9                                  for (i = dim - 1;i > 0; i--)
10                                  {
11                                      j = rand() % (i + 1);
12                                      t = a[i];
13                                      a[i] = a[j];
14                                      a[j] = t;
15                                     //swap(a[i], a[j]);
16                                  }
17                           }
18typedef void *Item;
19#include <stdio.h>
20#include <stdlib.h>
21#include "item.h"
22
23Item inputItem(){
24    int *p;
25    p=malloc(sizeof(int));
26    scanf("%d",p);
27    return p;
28}
29
30void outputItem(Item item){
31    int *p;
32    p=item;
33    printf("%d ",*p);
34}
35
36int cmpItem(Item item1,Item item2){
37    int *p1,*p2;
38    p1 = item1;
39    p2 = item2;
40    return *p1 - *p2;
41
42}
43void swap (Item pa, Item pb) {
44    Item t;
45    t = pa;
46    pa = pb;
47    pb = t;
48}
49

It works with these instructions:

1static Item *a; 
2static int dim = 3;
3
4a=malloc( dim * sizeof(Item);
5
6void random_array() {
7                                  int i , j;
8                                  Item t;
9                                  for (i = dim - 1;i > 0; i--)
10                                  {
11                                      j = rand() % (i + 1);
12                                      t = a[i];
13                                      a[i] = a[j];
14                                      a[j] = t;
15                                     //swap(a[i], a[j]);
16                                  }
17                           }
18typedef void *Item;
19#include <stdio.h>
20#include <stdlib.h>
21#include "item.h"
22
23Item inputItem(){
24    int *p;
25    p=malloc(sizeof(int));
26    scanf("%d",p);
27    return p;
28}
29
30void outputItem(Item item){
31    int *p;
32    p=item;
33    printf("%d ",*p);
34}
35
36int cmpItem(Item item1,Item item2){
37    int *p1,*p2;
38    p1 = item1;
39    p2 = item2;
40    return *p1 - *p2;
41
42}
43void swap (Item pa, Item pb) {
44    Item t;
45    t = pa;
46    pa = pb;
47    pb = t;
48}
49void swap (Item *pa, Item *pb) 
50{
51    Item t;
52    t = *pa;
53    *pa = *pb;
54    *pb = t;
55}
56

I know that with "typedef void *Item' Item t is like void *t and Item *a is like void **a, right? So with double pointers I have a dynamic array with many pointers thanks to a=malloc(numberelements*(sizeof(Item)); and with a[i]=malloc(sizeof(Item) every pointer points to a memory location with many bytes?

Here a image.

So for t I don't need malloc because with t = a[i] t points to memory location pointed from a[i], right? If yes, why do I have to use in my swap function t = *pa etc. instead of t = pa ? I have several doubts about double pointers as function parameters. I hope you can resolve that. Thanks in advance!

ANSWER

Answered 2020-May-14 at 00:29

Ok, let's start from here:

1static Item *a; 
2static int dim = 3;
3
4a=malloc( dim * sizeof(Item);
5
6void random_array() {
7                                  int i , j;
8                                  Item t;
9                                  for (i = dim - 1;i > 0; i--)
10                                  {
11                                      j = rand() % (i + 1);
12                                      t = a[i];
13                                      a[i] = a[j];
14                                      a[j] = t;
15                                     //swap(a[i], a[j]);
16                                  }
17                           }
18typedef void *Item;
19#include <stdio.h>
20#include <stdlib.h>
21#include "item.h"
22
23Item inputItem(){
24    int *p;
25    p=malloc(sizeof(int));
26    scanf("%d",p);
27    return p;
28}
29
30void outputItem(Item item){
31    int *p;
32    p=item;
33    printf("%d ",*p);
34}
35
36int cmpItem(Item item1,Item item2){
37    int *p1,*p2;
38    p1 = item1;
39    p2 = item2;
40    return *p1 - *p2;
41
42}
43void swap (Item pa, Item pb) {
44    Item t;
45    t = pa;
46    pa = pb;
47    pb = t;
48}
49void swap (Item *pa, Item *pb) 
50{
51    Item t;
52    t = *pa;
53    *pa = *pb;
54    *pb = t;
55}
56typedef int Item;  // Always get this backwards, need to check...
57
58void swap (Item *pa, Item *pb) 
59{
60    Item t;
61    t = *pa;
62    *pa = *pb;
63    *pb = t;
64}
65
66void foo()
67{
68    Item i= (Item), j=(Item)2;  // These casts are not needed, but help later explanations
69
70    // Must take address so swap can change original values of i and j.
71    swap(&i, &j);
72
73    Item *ip = &i;
74    Item *jp = &j;
75
76    // This also works because we do the dereference above.
77    swap(ip, jj);
78}
79

Either are fine. What about?

1static Item *a; 
2static int dim = 3;
3
4a=malloc( dim * sizeof(Item);
5
6void random_array() {
7                                  int i , j;
8                                  Item t;
9                                  for (i = dim - 1;i > 0; i--)
10                                  {
11                                      j = rand() % (i + 1);
12                                      t = a[i];
13                                      a[i] = a[j];
14                                      a[j] = t;
15                                     //swap(a[i], a[j]);
16                                  }
17                           }
18typedef void *Item;
19#include <stdio.h>
20#include <stdlib.h>
21#include "item.h"
22
23Item inputItem(){
24    int *p;
25    p=malloc(sizeof(int));
26    scanf("%d",p);
27    return p;
28}
29
30void outputItem(Item item){
31    int *p;
32    p=item;
33    printf("%d ",*p);
34}
35
36int cmpItem(Item item1,Item item2){
37    int *p1,*p2;
38    p1 = item1;
39    p2 = item2;
40    return *p1 - *p2;
41
42}
43void swap (Item pa, Item pb) {
44    Item t;
45    t = pa;
46    pa = pb;
47    pb = t;
48}
49void swap (Item *pa, Item *pb) 
50{
51    Item t;
52    t = *pa;
53    *pa = *pb;
54    *pb = t;
55}
56typedef int Item;  // Always get this backwards, need to check...
57
58void swap (Item *pa, Item *pb) 
59{
60    Item t;
61    t = *pa;
62    *pa = *pb;
63    *pb = t;
64}
65
66void foo()
67{
68    Item i= (Item), j=(Item)2;  // These casts are not needed, but help later explanations
69
70    // Must take address so swap can change original values of i and j.
71    swap(&i, &j);
72
73    Item *ip = &i;
74    Item *jp = &j;
75
76    // This also works because we do the dereference above.
77    swap(ip, jj);
78}
79typedef int******* Item;
80
81void swap (Item *pa, Item *pb) 
82{
83    Item t;
84    t = *pa;
85    *pa = *pb;
86    *pb = t;
87}
88
89void foo()
90{
91    Item i= (Item)1, j=(Item)2;
92
93    // Must take address so swap can change original values of i and j.
94    swap(&i, &j);
95
96    int *ip = &i;
97    int *jp = &j;
98
99    // This also works because we do the dereference above.
100    swap(ip, jp);
101}
102

Again, the type doesn't matter. It's how it's used. If you were to forget the &, the compiler would warn you about type mismatch.

Source https://stackoverflow.com/questions/61785612

Community Discussions contain sources that include Stack Exchange Network

Tutorials and Learning Resources in File Utils

Tutorials and Learning Resources are not available at this moment for File Utils

Share this Page

share link

Get latest updates on File Utils