FileBackedOutputStream 用例 (Guava)

发布于 2024-10-14 21:08:03 字数 345 浏览 3 评论 0原文

我从 Google Guava 库中发现了 FileBackedOutputStream 类,想知道它是否适合用作一种缓冲区:每天一次,我的 web 应用程序中的一个进程会生成数十个数千行(每行大约包含 100 个字符),然后上传到 FTP 服务器上的文件。我正在考虑使用 FileBackedOutputStream 对象首先写入所有这些字符串,然后使用 FileBackedOutputStream.getSupplier().getInput() 向我的 FTP 客户端提供对它们的访问权限,它返回一个InputStream。这是 FileBackedOutputStream 的正确用例吗?

I came across FileBackedOutputStream class from Google Guava library and was wondering if it's suitable to be used as a kind of a buffer: once every day, a process in my webapp generates tens of thousands of lines (each containing about 100characters) which are then uploaded to a file on an FTP server. I was thinking of using a FileBackedOutputStream object to first write all these strings to and then give access to them to my FTP client by using FileBackedOutputStream.getSupplier().getInput(), which returns an InputStream. Would this be a correct use case for FileBackedOutputStream?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

背叛残局 2024-10-21 21:08:03

是的,我认为这对于 FileBackedOutputStream 来说是一个可接受的用例。但是,我认为当您将 FileBackedOutputStream 与大小可能相差很大的数据一起使用时,它是最好的......对于可以容纳在内存中而没有问题的少量数据,您只想缓冲它们但对于大量数据,如果您尝试将其全部读入内存,可能会出现 OutOfMemoryError 错误,您需要切换到缓冲到文件。我认为这就是 FileBackedOutputStream 真正发挥作用的地方。我用它来缓冲上传的文件,我需要用它来做几件事。

Yes, I think that would be an acceptable use case for FileBackedOutputStream. However, I think FileBackedOutputStream is best when you're using it with data that may vary in size considerably... for small amounts of data that can fit in memory without a problem you want to just buffer them in memory but for large amounts of data that might give you an OutOfMemoryError if you try to read it all in to memory, you want to switch to buffering to a file. This is where FileBackedOutputStream really shines I think. I've used it for buffering uploaded files that I need to do several things with.

小糖芽 2024-10-21 21:08:03

我知道这是一篇相当旧的帖子,但以防万一您仍在使用上述类,请注意此漏洞,https://nvd.nist.gov/vuln/detail/CVE-2023-2976,其中使用旧版本创建的文件可能容易受到攻击,即其他方可以访问文件和/或目录(授权不当)

I know this is a rather old post, but just in case you are still using the above mentioned class, just be aware of this vulnerability, https://nvd.nist.gov/vuln/detail/CVE-2023-2976, where files created by using the older versions might be vulnerable to attack, namely files and/or directories may be accessible to other parties (improper authorization)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文