Returns the length of a file in bytes which exists in the HDFS (accounts for replication). @param filename @return length of the file in bytes @throws IOException
(String filename)
| 1237 | * @throws IOException |
| 1238 | */ |
| 1239 | public long fileSize(String filename) throws IOException { |
| 1240 | DataStorage dfs = pigContext.getDfs(); |
| 1241 | ElementDescriptor elem = dfs.asElement(filename); |
| 1242 | Map<String, Object> stats = elem.getStatistics(); |
| 1243 | long length = (Long) stats.get(ElementDescriptor.LENGTH_KEY); |
| 1244 | int replication = (Short) stats |
| 1245 | .get(ElementDescriptor.BLOCK_REPLICATION_KEY); |
| 1246 | |
| 1247 | return length * replication; |
| 1248 | } |
| 1249 | |
| 1250 | /** |
| 1251 | * Test whether a file exists. |