/** {@inheritDoc} */ @Override public int read() throws IOException { if (pos < maxLen) { int res = is.read(); if (res != -1) pos++; return res; } else return -1; }
/** {@inheritDoc} */ @Override public int read(@NotNull byte[] b, int off, int len) throws IOException { if (pos < maxLen) { len = (int)Math.min(len, maxLen - pos); int res = is.read(b, off, len); if (res != -1) pos += res; return res; } else return -1; }
@Override public Object call() throws Exception { IgfsInputStream in0 = igfs.open(FILE); in0.seek(blockSize * 2); try { in0.read(readBuf); } finally { U.closeQuiet(in0); } return null; } }, IOException.class,
/** {@inheritDoc} */ @Override public Object execute(IgniteFileSystem igfs, IgfsFileRange range, IgfsInputStream in) throws IOException { assert ignite != null; assert ses != null; assert ctx != null; in.seek(range.start()); byte[] buf = new byte[(int)range.length()]; int totalRead = 0; while (totalRead < buf.length) { int b = in.read(); assert b != -1; buf[totalRead++] = (byte)b; } String str = new String(buf); String[] chunks = str.split(" "); int ctr = 0; for (String chunk : chunks) { if (!chunk.isEmpty()) ctr++; } return F.t(range.length(), ctr); }
/** {@inheritDoc} */ @Override public void handleFile(String strPath) throws Exception { IgfsPath path = new IgfsPath(strPath); IgfsInputStream in; try { in = fs.open(path); } catch (IgfsPathNotFoundException ex) { System.out.println("file " + path.toString() + " not exist: " + ex); throw ex; } catch (IgniteException ex) { System.out.println("open file " + path.toString() + " failed: " + ex); throw ex; } try { for (int i = 0; i < size / dataBufer.capacity(); i++) in.read(dataBufer.array()); } catch (IOException ex) { System.out.println("read file " + path.toString() + " failed: " + ex); throw ex; } finally { in.close(); } }
/** * @throws Exception If failed. */ @Test public void testReadFragmentizing() throws Exception { IgniteFileSystem igfs = grid(0).fileSystem("igfs"); IgfsPath path = new IgfsPath("/someFile"); try (IgfsOutputStream out = igfs.create(path, true)) { // Write 10 groups. for (int i = 0; i < 10 * IGFS_GROUP_SIZE; i++) { byte[] data = new byte[IGFS_BLOCK_SIZE]; Arrays.fill(data, (byte)i); out.write(data); } } long start = System.currentTimeMillis(); do { try (IgfsInputStream in = igfs.open(path)) { for (int i = 0; i < 10 * IGFS_GROUP_SIZE; i++) { for (int j = 0; j < IGFS_BLOCK_SIZE; j++) assertEquals(i & 0xFF, in.read()); } assertEquals(-1, in.read()); } } while (System.currentTimeMillis() - start < 7000); }
/** * Runs query check result. * * @param expRes Expected result. * @param qry Query. * @throws Exception If failed. */ private void checkQuery(String expRes, String qry) throws Exception { assertEquals(0, executeHiveQuery("drop table if exists result")); assertEquals(0, executeHiveQuery( "create table result " + "row format delimited fields terminated by ' ' " + "stored as textfile " + "location '/result' as " + qry )); IgfsInputStream in = igfs.open(new IgfsPath("/result/000000_0")); byte[] buf = new byte[(int) in.length()]; in.read(buf); assertEquals(expRes, new String(buf)); }
int read = is.read(buf);
/** {@inheritDoc} */ @Override public int read() throws IOException { if (pos < maxLen) { int res = is.read(); if (res != -1) pos++; return res; } else return -1; }
/** {@inheritDoc} */ @Override public int read(@NotNull byte[] b, int off, int len) throws IOException { if (pos < maxLen) { len = (int)Math.min(len, maxLen - pos); int res = is.read(b, off, len); if (res != -1) pos += res; return res; } else return -1; }