8
8
import java .io .IOException ;
9
9
import java .io .InputStream ;
10
10
import java .io .OutputStream ;
11
+ import java .net .SocketException ;
11
12
import java .nio .charset .Charset ;
12
13
import java .nio .charset .UnsupportedCharsetException ;
13
14
import java .util .ArrayList ;
14
15
import java .util .HashMap ;
15
16
import java .util .List ;
16
17
import java .util .Map ;
17
- import java .util .Vector ;
18
18
19
19
import ch .ethz .ssh2 .channel .Channel ;
20
20
import ch .ethz .ssh2 .log .Logger ;
@@ -159,7 +159,7 @@ public void setCharset(String charset) throws IOException
159
159
{
160
160
if (charset == null )
161
161
{
162
- charsetName = charset ;
162
+ charsetName = null ;
163
163
return ;
164
164
}
165
165
@@ -239,11 +239,11 @@ private void readBytes(byte[] buff, int pos, int len) throws IOException
239
239
int count = is .read (buff , pos , len );
240
240
if (count < 0 )
241
241
{
242
- throw new IOException ("Unexpected end of sftp stream." );
242
+ throw new SocketException ("Unexpected end of sftp stream." );
243
243
}
244
244
if ((count == 0 ) || (count > len ))
245
245
{
246
- throw new IOException ("Underlying stream implementation is bogus!" );
246
+ throw new SocketException ("Underlying stream implementation is bogus!" );
247
247
}
248
248
len -= count ;
249
249
pos += count ;
@@ -396,7 +396,7 @@ public SFTPv3FileAttributes fstat(SFTPv3FileHandle handle) throws IOException
396
396
int rep_id = tr .readUINT32 ();
397
397
if (rep_id != req_id )
398
398
{
399
- throw new IOException ( "The server sent an invalid id field." );
399
+ throw new RequestMismatchException ( );
400
400
}
401
401
402
402
if (t == Packet .SSH_FXP_ATTRS )
@@ -406,7 +406,7 @@ public SFTPv3FileAttributes fstat(SFTPv3FileHandle handle) throws IOException
406
406
407
407
if (t != Packet .SSH_FXP_STATUS )
408
408
{
409
- throw new IOException ( "The SFTP server sent an unexpected packet type (" + t + ")" );
409
+ throw new PacketTypeException ( t );
410
410
}
411
411
412
412
int errorCode = tr .readUINT32 ();
@@ -435,7 +435,7 @@ private SFTPv3FileAttributes statBoth(String path, int statMethod) throws IOExce
435
435
int rep_id = tr .readUINT32 ();
436
436
if (rep_id != req_id )
437
437
{
438
- throw new IOException ( "The server sent an invalid id field." );
438
+ throw new RequestMismatchException ( );
439
439
}
440
440
441
441
if (t == Packet .SSH_FXP_ATTRS )
@@ -445,7 +445,7 @@ private SFTPv3FileAttributes statBoth(String path, int statMethod) throws IOExce
445
445
446
446
if (t != Packet .SSH_FXP_STATUS )
447
447
{
448
- throw new IOException ( "The SFTP server sent an unexpected packet type (" + t + ")" );
448
+ throw new PacketTypeException ( t );
449
449
}
450
450
451
451
int errorCode = tr .readUINT32 ();
@@ -511,7 +511,7 @@ public String readLink(String path) throws IOException
511
511
int rep_id = tr .readUINT32 ();
512
512
if (rep_id != req_id )
513
513
{
514
- throw new IOException ( "The server sent an invalid id field." );
514
+ throw new RequestMismatchException ( );
515
515
}
516
516
517
517
if (t == Packet .SSH_FXP_NAME )
@@ -528,7 +528,7 @@ public String readLink(String path) throws IOException
528
528
529
529
if (t != Packet .SSH_FXP_STATUS )
530
530
{
531
- throw new IOException ( "The SFTP server sent an unexpected packet type (" + t + ")" );
531
+ throw new PacketTypeException ( t );
532
532
}
533
533
534
534
int errorCode = tr .readUINT32 ();
@@ -549,12 +549,12 @@ private void expectStatusOKMessage(int id) throws IOException
549
549
int rep_id = tr .readUINT32 ();
550
550
if (rep_id != id )
551
551
{
552
- throw new IOException ( "The server sent an invalid id field." );
552
+ throw new RequestMismatchException ( );
553
553
}
554
554
555
555
if (t != Packet .SSH_FXP_STATUS )
556
556
{
557
- throw new IOException ( "The SFTP server sent an unexpected packet type (" + t + ")" );
557
+ throw new PacketTypeException ( t );
558
558
}
559
559
560
560
int errorCode = tr .readUINT32 ();
@@ -671,7 +671,7 @@ public String canonicalPath(String path) throws IOException
671
671
int rep_id = tr .readUINT32 ();
672
672
if (rep_id != req_id )
673
673
{
674
- throw new IOException ( "The server sent an invalid id field." );
674
+ throw new RequestMismatchException ( );
675
675
}
676
676
677
677
if (t == Packet .SSH_FXP_NAME )
@@ -690,7 +690,7 @@ public String canonicalPath(String path) throws IOException
690
690
691
691
if (t != Packet .SSH_FXP_STATUS )
692
692
{
693
- throw new IOException ( "The SFTP server sent an unexpected packet type (" + t + ")" );
693
+ throw new PacketTypeException ( t );
694
694
}
695
695
696
696
int errorCode = tr .readUINT32 ();
@@ -723,7 +723,7 @@ private List<SFTPv3DirectoryEntry> scanDirectory(byte[] handle) throws IOExcepti
723
723
int rep_id = tr .readUINT32 ();
724
724
if (rep_id != req_id )
725
725
{
726
- throw new IOException ( "The server sent an invalid id field." );
726
+ throw new RequestMismatchException ( );
727
727
}
728
728
729
729
if (t == Packet .SSH_FXP_NAME )
@@ -750,7 +750,7 @@ private List<SFTPv3DirectoryEntry> scanDirectory(byte[] handle) throws IOExcepti
750
750
751
751
if (t != Packet .SSH_FXP_STATUS )
752
752
{
753
- throw new IOException ( "The SFTP server sent an unexpected packet type (" + t + ")" );
753
+ throw new PacketTypeException ( t );
754
754
}
755
755
756
756
int errorCode = tr .readUINT32 ();
@@ -785,7 +785,7 @@ public final SFTPv3FileHandle openDirectory(String path) throws IOException
785
785
int rep_id = tr .readUINT32 ();
786
786
if (rep_id != req_id )
787
787
{
788
- throw new IOException ( "The server sent an invalid id field." );
788
+ throw new RequestMismatchException ( );
789
789
}
790
790
791
791
if (t == Packet .SSH_FXP_HANDLE )
@@ -796,7 +796,7 @@ public final SFTPv3FileHandle openDirectory(String path) throws IOException
796
796
797
797
if (t != Packet .SSH_FXP_STATUS )
798
798
{
799
- throw new IOException ( "The SFTP server sent an unexpected packet type (" + t + ")" );
799
+ throw new PacketTypeException ( t );
800
800
}
801
801
802
802
int errorCode = tr .readUINT32 ();
@@ -819,7 +819,7 @@ private String expandString(byte[] b, int off, int len)
819
819
}
820
820
else
821
821
{
822
- sb .append ("{0x" + Integer .toHexString (c ) + "}" );
822
+ sb .append (String . format ( "{0x%s}" , Integer .toHexString (c )) );
823
823
}
824
824
}
825
825
@@ -1231,7 +1231,7 @@ public SFTPv3FileHandle openFile(String fileName, int flags, SFTPv3FileAttribute
1231
1231
int rep_id = tr .readUINT32 ();
1232
1232
if (rep_id != req_id )
1233
1233
{
1234
- throw new IOException ( "The server sent an invalid id field." );
1234
+ throw new RequestMismatchException ( );
1235
1235
}
1236
1236
1237
1237
if (t == Packet .SSH_FXP_HANDLE )
@@ -1242,7 +1242,7 @@ public SFTPv3FileHandle openFile(String fileName, int flags, SFTPv3FileAttribute
1242
1242
1243
1243
if (t != Packet .SSH_FXP_STATUS )
1244
1244
{
1245
- throw new IOException ( "The SFTP server sent an unexpected packet type (" + t + ")" );
1245
+ throw new PacketTypeException ( t );
1246
1246
}
1247
1247
1248
1248
int errorCode = tr .readUINT32 ();
@@ -1396,7 +1396,7 @@ public int read(SFTPv3FileHandle handle, long fileOffset, byte[] dst, int dstoff
1396
1396
OutstandingReadRequest req = pendingReadQueue .remove (tr .readUINT32 ());
1397
1397
if (null == req )
1398
1398
{
1399
- throw new IOException ( "The server sent an invalid id field." );
1399
+ throw new RequestMismatchException ( );
1400
1400
}
1401
1401
// Evaluate the answer
1402
1402
if (t == Packet .SSH_FXP_STATUS )
@@ -1458,7 +1458,7 @@ else if (t == Packet.SSH_FXP_DATA)
1458
1458
}
1459
1459
else
1460
1460
{
1461
- throw new IOException ( "The SFTP server sent an unexpected packet type (" + t + ")" );
1461
+ throw new PacketTypeException ( t );
1462
1462
}
1463
1463
}
1464
1464
// Should never reach here.
@@ -1539,7 +1539,7 @@ private void readStatus() throws IOException
1539
1539
OutstandingStatusRequest status = pendingStatusQueue .remove (tr .readUINT32 ());
1540
1540
if (null == status )
1541
1541
{
1542
- throw new IOException ( "The server sent an invalid id field." );
1542
+ throw new RequestMismatchException ( );
1543
1543
}
1544
1544
1545
1545
// Evaluate the answer
@@ -1560,7 +1560,7 @@ private void readStatus() throws IOException
1560
1560
listener .read (msg );
1561
1561
throw new SFTPException (msg , code );
1562
1562
}
1563
- throw new IOException ( "The SFTP server sent an unexpected packet type (" + t + ")" );
1563
+ throw new PacketTypeException ( t );
1564
1564
}
1565
1565
1566
1566
private void readPendingReadStatus () throws IOException
@@ -1575,7 +1575,7 @@ private void readPendingReadStatus() throws IOException
1575
1575
OutstandingReadRequest status = pendingReadQueue .remove (tr .readUINT32 ());
1576
1576
if (null == status )
1577
1577
{
1578
- throw new IOException ( "The server sent an invalid id field." );
1578
+ throw new RequestMismatchException ( );
1579
1579
}
1580
1580
1581
1581
// Evaluate the answer
@@ -1600,7 +1600,7 @@ private void readPendingReadStatus() throws IOException
1600
1600
listener .read (msg );
1601
1601
throw new SFTPException (msg , code );
1602
1602
}
1603
- throw new IOException ( "The SFTP server sent an unexpected packet type (" + t + ")" );
1603
+ throw new PacketTypeException ( t );
1604
1604
}
1605
1605
1606
1606
/**
0 commit comments