Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update usage of FileInput/OutputStream #1837

Merged
merged 3 commits into from
Apr 28, 2017
Merged

Conversation

eltimn
Copy link
Member

@eltimn eltimn commented Apr 20, 2017

Fixes #1835

I haven't been able to directly test this yet, but I started to upgrade our app to use Scala 2.12 and will as soon as that's done.

Copy link
Member

@farmdawgnation farmdawgnation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty straightforward. Left you one question, but not major.

@@ -85,7 +86,8 @@ trait IoHelpers {
/**
* Read an entire file into an Array[Byte]
*/
def readWholeFile(file: File): Array[Byte] = readWholeStream(new FileInputStream(file))
def readWholeFile(file: File): Array[Byte] = readWholeStream(Files.newInputStream(file.toPath))
def readWholeFile(path: Path): Array[Byte] = readWholeStream(Files.newInputStream(path))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the scaladoc appear for both methods if they're grouped like this or should we copy it to be above the second instance, too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. I'll try it locally and see what it looks like.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did not appear, so I copied it.

Copy link
Member

@farmdawgnation farmdawgnation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@farmdawgnation farmdawgnation modified the milestone: 3.1.0-M3 Apr 26, 2017
@farmdawgnation
Copy link
Member

@eltimn Are we waiting on a first-hand testing report from you or is this good to merge?

@eltimn
Copy link
Member Author

eltimn commented Apr 26, 2017

I did get our app upgraded to scala 2.12, but I'd need to publish a few lift modules compiled against 3.1 before I could test this.

I did make these same changes to our app without issues, so I'm good with merging it.

@eltimn
Copy link
Member Author

eltimn commented Apr 28, 2017

I added a spec to test readWholeFile, which is what I mainly wanted to make sure still worked properly.

@farmdawgnation
Copy link
Member

Sweet. I say we ship this, then.

@farmdawgnation farmdawgnation merged commit 44e605a into master Apr 28, 2017
@farmdawgnation farmdawgnation deleted the tcn_issue_1835 branch April 28, 2017 12:17
@@ -284,14 +284,14 @@ FileParamHolder(name, mimeType, fileName)
* @param localFile The local copy of the uploaded file
*/
class OnDiskFileParamHolder(override val name: String, override val mimeType: String,
override val fileName: String, val localFile: File) extends
override val fileName: String, val localFile: Path) extends
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whelp, I missed this guy. This will break all consumers of OnDiskFileParamHolder. Is there a way to get from Path to File? If not, I suggest we revert the changes to OnDiskFileParamHolder. If yes, I suggest we rename this parameter localPath and provide a localFile accessor that returns a File as existing code will expect. We can mark that one deprecated if we really want to.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an apply function with File, so it shouldn't break anything. Also, there's a toPath function on File, and a toFile function on Path that can convert either way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1852 (comment) . Folks are using .localFile directly, and passing it to things that expect a File. Moreover, localFile is a poor name for something that isn't a File, but rather a Path, IMO.

I'll work up a PR to make this API-compatible, should only be a couple of lines.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that's not a case class, though. Do I need to change that to a constructor?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what I did wrong now. Thanks for fixing it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll probably add a constructor overload as well, good point. I also missed that it wasn't a case class hah. I doubt anyone is using the constructor directly, but better safe than sorry.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, so the reason FileInputStream and FileOutputStream are “considered harmful” in the Cloudbees post is because they use finalizers. But OnDiskFileParamHolder also has a finalizer. I think this is probably still a win, but worth mentioning.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The finalize function is on OnDiskFileParamHolder, not on the FileStream class, though. I would assume that's a bit different, although I guess I don't know exactly how having finalizers affect GC.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah not sure either. Will keep it in mind in case anything around this comes up in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants