[jcifs] Need help loading a file...please
Laura McCord
mccordl at southwestern.edu
Thu Jun 28 13:23:54 GMT 2007
Well, I think I am getting a little but closer. It at least is giving me the total number of bytes transferred. So, with this said perhaps it is actually getting the image. However, I still can't get the image to actually display.
My logs indicate:
######################
172176 bytes transfered in 0 seconds at 172Kbytes/sec
The way I am testing it is by using a jsp file:
<img src="image?file=Image002/20060725/273251.jpg" />
protected void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
// Get file name from request.
String imageFileName = req.getParameter("file");
// Check if file name is supplied to the request.
if (imageFileName == null) {
return;
}
System.err.println(imageFileName);
// Prepare streams.
// Open image file.
Config.setProperty("jcifs.netbios.wins", "ipaddress");
Config.setProperty("jcifs.smb.client.domain", "domain");
Config.setProperty("jcifs.smb.client.username", "user");
Config.setProperty("jcifs.smb.client.password", "secret");
SmbFile f = new SmbFile("smb://ipaddress/idworks/" + imageFileName);
SmbFileInputStream in = new SmbFileInputStream( f );
res.setContentType("image/jpeg");
FileOutputStream out = new FileOutputStream( f.getName() );
long t0 = System.currentTimeMillis();
byte[] b = new byte[8192];
int n, tot = 0;
long t1 = t0;
while(( n = in.read( b )) > 0 ) {
out.write( b, 0, n );
tot += n;
System.err.print( '#' );
}
long t = System.currentTimeMillis() - t0;
System.err.println();
System.err.println( tot + " bytes transfered in " + ( t / 1000 ) + " seconds at " + (( tot / 1000 ) / Math.max( 1, ( t / 1000 ))) + "Kbytes/sec" );
in.close();
out.close();
}
Quoting Michael B Allen <miallen at ioplex.com>:
> Try the Get.java example. If that works, work backward from there.
>
> On Wed, 27 Jun 2007 16:53:41 -0500
> Laura McCord <mccordl at southwestern.edu> wrote:
>
>> I had already tried that but it didn't work, a 0 is still returned for the contentLength.
>>
>>
>>
>> Quoting Michael B Allen <miallen at ioplex.com>:
>>
>> > On Wed, 27 Jun 2007 14:22:58 -0500
>> > Laura McCord <mccordl at southwestern.edu> wrote:
>> >
>> >> The only reason why I think it's JCIFS is because after I use "in =
>> >> new SmbFileInputStream" and I try to do "int contentLength =
>> >> in.available();" I am getting nothing as if the InputStream is empty.
>> >> To me that sounds like there is a problem with me loading the file
>> >> using jcifs, don't you think?
>> >
>> > I think you should look at the API documentation:
>> >
>> > "This stream class is unbuffered. Therefore this method will always
>> > return 0 for streams connected to regular files."
>> >
>> > I think you want to wrap the SmbFileInputStream in a BufferedInputStream:
>> >
>> > in = new BufferedInputStream(new SmbFileInputStream(...));
>> > in.available()
>> >
>> >>
>> >> Thanks,
>> >> Laura
>> >>
>> >> Quoting Michael B Allen <miallen at ioplex.com>:
>> >>
>> >> > Hi Laura,
>> >> >
>> >> > What you're trying to do doesn't really have anything to do with jCIFS. I
>> >> > suggest you try the Java forums java.sun.com.
>> >> >
>> >> > Mike
>> >> >
>> >> > On Wed, 27 Jun 2007 14:02:13 -0500
>> >> > Laura McCord <mccordl at southwestern.edu> wrote:
>> >> >
>> >> >> I have posted this question a couple times with no luck.
>> >> >>
>> >> >> I have made a connection to the filesystem and my file was found.
>> >> >> However, when I use "in = new SmbFileInputStream", is the file
>> >> >> loaded or do I need to read in the file still? I am confused...
>> >> >> PLease help me.... I have been working on this for two months.
>> >> >>
>> >> >>
>> >> >>
>> >> >> SmbFileInputStream in = null;
>> >> >> System.err.println("Test1"); //make sure methood
>> >> >> is being called
>> >> >> Config.setProperty("jcifs.netbios.wins", "ip");
>> >> >> Config.setProperty("jcifs.smb.client.domain", "domain");
>> >> >> Config.setProperty("jcifs.smb.client.username", "user");
>> >> >> Config.setProperty("jcifs.smb.client.password", "secret");
>> >> >> try{
>> >> >> in = new SmbFileInputStream("smb://ip/idworks/"
>> >> >> + imgPath);
>> >> >> }catch(Exception e){
>> >> >> e.printStackTrace();
>> >> >> }
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >> > --
>> >> > Michael B Allen
>> >> > PHP Active Directory Kerberos SSO
>> >> > http://www.ioplex.com/
>> >> >
>> >>
>> >>
>> >
>> >
>> > --
>> > Michael B Allen
>> > PHP Active Directory Kerberos SSO
>> > http://www.ioplex.com/
>> >
>>
>>
>
>
> --
> Michael B Allen
> PHP Active Directory Kerberos SSO
> http://www.ioplex.com/
>
More information about the jcifs
mailing list