(String path, String type)
| 121 | } |
| 122 | |
| 123 | public static ByteSource getFileByteSource(String path, String type) throws IOException { |
| 124 | char nullChar = 0; |
| 125 | ByteSource byteSource = Files.asByteSource(new File(path)); |
| 126 | if (ConstantVal.NONE.equals(type)) { |
| 127 | return byteSource; |
| 128 | } |
| 129 | // todo: refactor the below code to extract a method like obj.partition in python |
| 130 | byte[] fileWithHeader = byteSource.read(); |
| 131 | byte[] header = new byte[type.getBytes(Charsets.UTF_8).length]; |
| 132 | byte[] nullBytes = new byte[Chars.toByteArray(nullChar).length]; |
| 133 | byte[] fileContent = new byte[fileWithHeader.length - header.length - nullBytes.length]; |
| 134 | ByteBuffer fileWithHeaderBuffer = ByteBuffer.wrap(fileWithHeader); |
| 135 | fileWithHeaderBuffer.get(header, 0, header.length); |
| 136 | log.debug("current object type is {}:", new String(header, Charsets.UTF_8)); |
| 137 | fileWithHeaderBuffer.get(nullBytes, 0, nullBytes.length); |
| 138 | fileWithHeaderBuffer.get(fileContent, 0, fileContent.length); |
| 139 | return ByteSource.wrap(fileContent); |
| 140 | } |
| 141 | |
| 142 | |
| 143 |
no outgoing calls
no test coverage detected