@Override public int read() throws IOException { if (index >= length) fillBuffer(); if (index >= length) return -1; return 0xff & buffer[index++]; }
public InputStream getInputStream() throws ResourceStreamNotFoundException { try { return new Base64.InputStream(new ReaderInputStream(reader, "utf-8"), Base64.DECODE); } catch (UnsupportedEncodingException e) { throw new OntopiaRuntimeException(e); } }
@Override public InputStream getInputStream() throws ResourceStreamNotFoundException { try { return new Base64InputStream(new ReaderInputStream(reader, "utf-8"), false); } catch (UnsupportedEncodingException e) { throw new OntopiaRuntimeException(e); } }
public void _testBinaryReader() throws Exception { // read file and store in occurrence String file = TestFileUtils.getTestInputFile("various", "blob.gif"); Reader ri = new InputStreamReader(new Base64InputStream(new FileInputStream(file), true), "utf-8"); occurrence.setReader(ri, file.length(), DataTypes.TYPE_BINARY); assertTrue("Occurrence datatype is incorrect", Objects.equals(DataTypes.TYPE_BINARY, occurrence.getDataType())); // read and decode occurrence content Reader ro = occurrence.getReader(); assertTrue("Reader value is null", ro != null); InputStream in = new Base64InputStream(new ReaderInputStream(ro, "utf-8"), false); try { OutputStream out = new FileOutputStream("/tmp/blob.gif"); try { IOUtils.copy(in, out); } finally { out.close(); } } finally { in.close(); } }
@Override public int read(byte[] data, int off, int len) throws IOException { if (index >= length) fillBuffer(); if (index >= length) return -1; int amount = Math.min(len, length - index); System.arraycopy(buffer, index, data, off, amount); index += amount; return amount; }