EgorKulikov / idea-chelper

Automatically exported from code.google.com/p/idea-chelper
112 stars 59 forks source link

Change FileInputStream to ResourceStream #63

Open asgarj opened 6 years ago

asgarj commented 6 years ago

When the input stream is from file, currently it's generating code as below:

try {
    inputStream = new FileInputStream("filename.in");
}

This is not robust, namely, it's only trying to read files from the current directory. However, it'd be good if it reads resource from anywhere in classpath.

asgarj commented 6 years ago

I have created a small patch for this, but unable to push my changes to remote. Permission denied. @EgorKulikov Can you grant me access?

EgorKulikov commented 6 years ago

Can you provide use case? Any online judge with such strange input/output? Also if you want to contribute you need to fork and then create pull request, not just push to master

asgarj commented 6 years ago

The use case is, for instance, FB HackerCup where time is running and you have only few minutes to submit. In the current approach, you have to download and move the file to the same directory as Main.java to be able to run it. Otherwise, you get FileNotFoundException. On the other hand, if you read it as resource stream #64, you can read file from wherever it is, given that you have it in classpath. This saves time since you don't have to move the file. Also, code looks simpler, just one-liner, no need to catch anything.

Thanks @EgorKulikov for helping re contribution, I was trying to push my local issue branch to your repo, not my forked one. I have now created PR #64.