@@ -42,18 +42,18 @@ public ResponseEntity<byte[]> prepareContent(String fileName, String fileType, S
42
42
if (range == null ) {
43
43
return ResponseEntity .status (HttpStatus .OK )
44
44
.header (CONTENT_TYPE , VIDEO_CONTENT + fileType )
45
- .header (CONTENT_LENGTH , String .valueOf (fileSize - 1 ))
46
- .body (readByteRange (fullFileName , rangeStart , fileSize )); // Read the object and convert it as bytes
45
+ .header (CONTENT_LENGTH , String .valueOf (fileSize ))
46
+ .body (readByteRange (fullFileName , rangeStart , fileSize - 1 )); // Read the object and convert it as bytes
47
47
}
48
48
String [] ranges = range .split ("-" );
49
49
rangeStart = Long .parseLong (ranges [0 ].substring (6 ));
50
50
if (ranges .length > 1 ) {
51
51
rangeEnd = Long .parseLong (ranges [1 ]);
52
52
} else {
53
- rangeEnd = fileSize ;
53
+ rangeEnd = fileSize - 1 ;
54
54
}
55
55
if (fileSize < rangeEnd ) {
56
- rangeEnd = fileSize ;
56
+ rangeEnd = fileSize - 1 ;
57
57
}
58
58
data = readByteRange (fullFileName , rangeStart , rangeEnd );
59
59
} catch (IOException e ) {
@@ -65,7 +65,7 @@ public ResponseEntity<byte[]> prepareContent(String fileName, String fileType, S
65
65
.header (CONTENT_TYPE , VIDEO_CONTENT + fileType )
66
66
.header (ACCEPT_RANGES , BYTES )
67
67
.header (CONTENT_LENGTH , contentLength )
68
- .header (CONTENT_RANGE , BYTES + " " + rangeStart + "-" + ( rangeEnd - 1 ) + "/" + fileSize )
68
+ .header (CONTENT_RANGE , BYTES + " " + rangeStart + "-" + rangeEnd + "/" + fileSize )
69
69
.body (data );
70
70
71
71
@@ -90,8 +90,8 @@ public byte[] readByteRange(String filename, long start, long end) throws IOExce
90
90
bufferedOutputStream .write (data , 0 , nRead );
91
91
}
92
92
bufferedOutputStream .flush ();
93
- byte [] result = new byte [(int ) (end - start )];
94
- System .arraycopy (bufferedOutputStream .toByteArray (), (int ) start , result , 0 , ( int ) ( end - start ) );
93
+ byte [] result = new byte [(int ) (end - start ) + 1 ];
94
+ System .arraycopy (bufferedOutputStream .toByteArray (), (int ) start , result , 0 , result . length );
95
95
return result ;
96
96
}
97
97
}
0 commit comments