Skip to content

Instantly share code, notes, and snippets.

@aurorapar
Created April 6, 2018 00:59
Show Gist options
  • Save aurorapar/afe57fa05d13a895f3992daa7fd55b7d to your computer and use it in GitHub Desktop.
Save aurorapar/afe57fa05d13a895f3992daa7fd55b7d to your computer and use it in GitHub Desktop.
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