English 中文(简体)
Java apache Commons FTP, how to的图像档案下载到BufferedImage
原标题:Java apache commons FTP, how to download image file to BufferedImage

因此,我试图从FTP网站下载一个图像文件,从中获取一些元数据,然后将双元数据带回一个使用“游戏”的网页! 框架。 这里是一部基本法典,在控制人的行动中使用(消除了所有对简便的错误检查):

FTPClient ftp = new FTPClient();
ftp.connect(site.host, site.port);
ftp.login(site.username, site.password);
InputStream is = ftp.retrieveFileStream("somefile.png");
Response.current().contentType = "image/png";
renderBinary(is);

我知道,投入流的真正类型是SocketInputStream,是否有特别需要做才能使用?

我也试图这样做:

BufferedImage bimg = ImageIO.read(is);

但是,双星显示为无效,因此我相信,投入流的数据并不有效。

Does anyone have any experience doing this and can point me in the right direction?

最佳回答

您可能需要将<代码>SocketInputStream改为Image InputStream。 这里有关于<代码>ImageIO.read()的javadoc,它解释了为什么你没有:

Returns a BufferedImage as the result of decoding a supplied InputStream with an ImageReader chosen automatically from among those currently registered. The InputStream is wrapped in an ImageInputStream. If no registered ImageReader claims to be able to read the resulting stream, null is returned.

The current cache settings from getUseCacheand getCacheDirectory will be used to control caching in the ImageInputStream that is created.

This method does not attempt to locate ImageReaders that can read directly from an InputStream; that may be accomplished using IIORegistry and ImageReaderSpi.

This method does not close the provided InputStream after the read operation has completed; it is the responsibility of the caller to close the stream, if desired.

因此,我假定<代码>ImageReader无法读到您的行文,因此,你从电话中拿不到。

<>>>>>

可能要:

BufferedImage bimg = ImageIO.read(ImageIO.createImageInputStream(yourSocketInputStream));

你们是否做了这项工作?

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签