Reads the given text stream and compressed its content.

@param stream The input stream
@return A byte array containing the GZIP-compressed content of the stream
@throws IOException If an error ocurred
331044
private byte[] readStreamCompressed(InputStream stream) throws IOException
    {
        ByteArrayOutputStream bao    = new ByteArrayOutputStream();
        GZIPOutputStream      gos    = new GZIPOutputStream(bao);
        OutputStreamWriter    output = new OutputStreamWriter(gos);
        BufferedReader        input  = new BufferedReader(new InputStreamReader(stream));
        String                line;

        while ((line = input.readLine()) != null)
        {
            output.write(line);
            output.write('\n');
        }
        input.close();
        stream.close();
        output.close();
        gos.close();
        bao.close();
        return bao.toByteArray();
    }
106353
public static byte[] readBytes(InputStream in) throws IORuntimeException {
		final FastByteArrayOutputStream out = new FastByteArrayOutputStream();
		copy(in, out);
		return out.toByteArray();
	}
348471
static public byte[] unzip(InputStream in) throws IOException {
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		CopyUtil.copy(new GZIPInputStream(in), bos);
		return bos.toByteArray();
	}
525857
@Trivial
    private static byte[] getBytes(InputStream stream, int knownSize) throws IOException {
        try {
            if (knownSize == -1) {
                ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
                try {
                    byte[] bytes = new byte[1024];
                    int read;
                    while (0 <= (read = stream.read(bytes)))
                        byteOut.write(bytes, 0, read);

                    return byteOut.toByteArray();
                } finally {
                    Util.tryToClose(byteOut);
                }
            } else {
                byte[] bytes = new byte[knownSize];
                int read;
                int offset = 0;
                while (knownSize > 0 && (read = stream.read(bytes, offset, knownSize)) > 0) {
                    offset += read;
                    knownSize -= read;
                }

                return bytes;
            }
        } finally {
            Util.tryToClose(stream);
        }
    }
1072956
InputStream getInputStream() throws IOException {
        switch (filetype) {
            case GZ:
                LOG.debug("Decompressing .gz file");
                return new GzipCompressorInputStream(new FileInputStream(compressedFile));
            case BZ2:
                LOG.debug("Decompressing .bz2 file");
                return new BZip2CompressorInputStream(new FileInputStream(compressedFile));
        }
        return null;
    }
1060943
private void copyToStream(String txt, OutputStream stream) throws IOException {
        if (txt != null) {
            stream.write(txt.getBytes());
        }
    }
439124
@SuppressWarnings("deprecation")
  public static byte[] readBytes(DataInputStream in) throws IOException {
    UTF8 ustr = TL_DATA.get().U_STR;
    ustr.readFields(in);
    int len = ustr.getLength();
    byte[] bytes = new byte[len];
    System.arraycopy(ustr.getBytes(), 0, bytes, 0, len);
    return bytes;
  }
240039
public static byte[] gzipUncompress(byte[] bytes) {
		if (bytes == null || bytes.length == 0) {
			return null;
		}
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		ByteArrayInputStream in = new ByteArrayInputStream(bytes);
		try {
			GZIPInputStream ungzip = new GZIPInputStream(in);
			byte[] buffer = new byte[256];
			int n;
			while ((n = ungzip.read(buffer)) >= 0) {
				out.write(buffer, 0, n);
			}
		} catch (IOException e) {
		}

		return out.toByteArray();
	}
1249763
public InputStream read() throws IOException {
        if(file.exists())
            try {
                return Files.newInputStream(file.toPath());
            } catch (InvalidPathException e) {
                throw new IOException(e);
            }

        // check if the compressed file exists
        if(gz.exists())
            try {
                return new GZIPInputStream(Files.newInputStream(gz.toPath()));
            } catch (InvalidPathException e) {
                throw new IOException(e);
            }

        // no such file
        throw new FileNotFoundException(file.getName());
    }
361898
public static String readString(final InputStream stream) throws IOException {
        InputStreamReader br = null;
        StringBuilder sb = new StringBuilder();
        try {
            br = new InputStreamReader(stream);

            int got;
            while (!Thread.currentThread().isInterrupted()) {
                got = br.read();
                if (got == -1) {
                    break;
                }

                sb.append((char) got);
            }
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (final IOException ex) {
                }
            }

        }

        return sb.toString();
    }
7099
@SuppressWarnings("unchecked")
    private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
        stream.defaultReadObject();
        this.properties = (Map<Object, Object>) stream.readObject();
    }
262754
public static byte[] loadFromStream(InputStream stream) {
		try {
			BufferedInputStream bis = new BufferedInputStream(stream);
			int size = 2048;
			byte[] theData = new byte[size];
			int dataReadSoFar = 0;
			byte[] buffer = new byte[size / 2];
			int read = 0;
			while ((read = bis.read(buffer)) != -1) {
				if ((read + dataReadSoFar) > theData.length) {
					// need to make more room
					byte[] newTheData = new byte[theData.length * 2];
					// System.out.println("doubled to " + newTheData.length);
					System.arraycopy(theData, 0, newTheData, 0, dataReadSoFar);
					theData = newTheData;
				}
				System.arraycopy(buffer, 0, theData, dataReadSoFar, read);
				dataReadSoFar += read;
			}
			bis.close();
			// Resize to actual data read
			byte[] returnData = new byte[dataReadSoFar];
			System.arraycopy(theData, 0, returnData, 0, dataReadSoFar);
			return returnData;
		}
		catch (IOException e) {
			throw new ReloadException("Unexpectedly unable to load bytedata from input stream", e);
		}
	}
6358
private static InputStreamWithMetadata compressStreamWithGZIPNoDigest(
      InputStream inputStream) throws SnowflakeSQLException
  {
    try
    {
      FileBackedOutputStream tempStream =
          new FileBackedOutputStream(MAX_BUFFER_SIZE, true);

      CountingOutputStream countingStream =
          new CountingOutputStream(tempStream);

      // construct a gzip stream with sync_flush mode
      GZIPOutputStream gzipStream;

      gzipStream = new GZIPOutputStream(countingStream, true);

      IOUtils.copy(inputStream, gzipStream);

      inputStream.close();

      gzipStream.finish();
      gzipStream.flush();

      countingStream.flush();

      return new InputStreamWithMetadata(countingStream.getCount(),
                                         null, tempStream);

    }
    catch (IOException ex)
    {
      logger.error("Exception compressing input stream", ex);

      throw new SnowflakeSQLException(ex, SqlState.INTERNAL_ERROR,
                                      ErrorCode.INTERNAL_ERROR.getMessageCode(),
                                      "error encountered for compression");
    }

  }
477645
public Result<String> extractRawText(InputStream stream) throws IOException {
        return new InternalDocumentConverter(options).extractRawText(stream).toResult();
    }
882649
public static byte[] encode(final byte[] data) throws IOException {
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        GZIPOutputStream gzOut = null;
        try {
            gzOut = new GZIPOutputStream(byteOut);
            gzOut.write(data);
            gzOut.close();
            byteOut.close();
            return byteOut.toByteArray();
        } finally {
            gzOut.close();
            byteOut.close();
        }
    }
157027
public Collection parse(InputStream stream) throws IOException {
        return parse(new BufferedReader(new InputStreamReader(stream, Charsets.UTF_8)));
    }
286262
private InputStream prepareInputStream(InputStream stream) throws IOException
   {
      InputStream result;
      BufferedInputStream bis = new BufferedInputStream(stream);
      readHeaderProperties(bis);
      if (isCompressed())
      {
         result = new InflaterInputStream(bis);
      }
      else
      {
         result = bis;
      }
      return result;
   }