Created
April 6, 2018 00:59
-
-
Save aurorapar/afe57fa05d13a895f3992daa7fd55b7d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void read(ByteArrayOutputStream sendStream, File file, String mode) | |
{ | |
switch(mode) | |
{ | |
case "octet": | |
try | |
{ | |
FileInputStream fileStream = new FileInputStream(file); | |
int remaining = fileStream.available() - ((Client.BUFFER_SIZE-4)*Client.filePosition); | |
debug("Remaining bytes: " + remaining); | |
int size = 0; | |
if(remaining > (Client.BUFFER_SIZE-4)) | |
{ | |
size = Client.BUFFER_SIZE - 4; | |
} | |
else | |
{ | |
size = remaining; | |
} | |
debug("Reading bytes: "+size); | |
byte[] data = new byte[size]; | |
debug(" " + size); | |
int offset = Client.filePosition * (Client.BUFFER_SIZE-4); | |
debug("Offsetting by: "+offset); | |
fileStream.read(data, offset, size); | |
debug("After read: " + fileStream.available()); | |
sendStream.write(data); | |
Client.filePosition++; | |
} | |
catch(Exception e) | |
{ | |
debug(e.toString()); | |
} | |
break; | |
case "netascii": | |
debug("Netascii mode"); | |
break; | |
default: | |
System.out.println("Invalid mode specified"); | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment