Java Code Examples for org.apache.commons.io.Charsets#toCharset()

The following examples show how to use org.apache.commons.io.Charsets#toCharset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogServiceMonitorRetriever.java    From Thunder with Apache License 2.0 5 votes vote down vote up
public List<MonitorStat> retrieve(String traceId, String filePath, String encoding) throws Exception {
    if (StringUtils.isEmpty(traceId)) {
        throw new MonitorException("Trace ID is null");
    }

    if (StringUtils.isEmpty(filePath)) {
        throw new MonitorException("File path is null");
    }

    List<MonitorStat> monitorStatList = new ArrayList<MonitorStat>();

    String key = "\"" + ThunderConstant.TRACE_ID + "\":\"" + traceId + "\"";

    InputStream inputStream = new FileInputStream(filePath);
    InputStreamReader inputStreamReader = new InputStreamReader(inputStream, Charsets.toCharset(encoding));
    BufferedReader bufferedReader = IOUtils.toBufferedReader(inputStreamReader);
    String line = bufferedReader.readLine();
    while (line != null) {
        if (line.contains(key)) {
            line = line.substring(line.indexOf("{"));
            try {
                MonitorStat monitorStat = create(line);
                monitorStatList.add(monitorStat);
            } catch (Exception e) {
                LOG.error("Create MonitorStat failed", e);
            }
        }
        line = bufferedReader.readLine();
    }

    sort(monitorStatList);

    IOUtils.closeQuietly(bufferedReader);
    IOUtils.closeQuietly(inputStreamReader);
    IOUtils.closeQuietly(inputStream);

    return monitorStatList;
}
 
Example 2
Source File: UnstructuredStorageWriterUtil.java    From DataLink with Apache License 2.0 4 votes vote down vote up
/**
 * check parameter: writeMode, encoding, compress, filedDelimiter
 * */
public static void validateParameter(Configuration writerConfiguration) {
    // writeMode check
    String writeMode = writerConfiguration.getNecessaryValue(
            Key.WRITE_MODE,
            UnstructuredStorageWriterErrorCode.REQUIRED_VALUE);
    writeMode = writeMode.trim();
    Set<String> supportedWriteModes = Sets.newHashSet("truncate", "append",
            "nonConflict");
    if (!supportedWriteModes.contains(writeMode)) {
        throw DataXException
                .asDataXException(
                        UnstructuredStorageWriterErrorCode.ILLEGAL_VALUE,
                        String.format(
                                "仅支持 truncate, append, nonConflict 三种模式, 不支持您配置的 writeMode 模式 : [%s]",
                                writeMode));
    }
    writerConfiguration.set(Key.WRITE_MODE, writeMode);

    // encoding check
    String encoding = writerConfiguration.getString(Key.ENCODING);
    if (StringUtils.isBlank(encoding)) {
        // like "  ", null
        LOG.warn(String.format("您的encoding配置为空, 将使用默认值[%s]",
                Constant.DEFAULT_ENCODING));
        writerConfiguration.set(Key.ENCODING, Constant.DEFAULT_ENCODING);
    } else {
        try {
            encoding = encoding.trim();
            writerConfiguration.set(Key.ENCODING, encoding);
            Charsets.toCharset(encoding);
        } catch (Exception e) {
            throw DataXException.asDataXException(
                    UnstructuredStorageWriterErrorCode.ILLEGAL_VALUE,
                    String.format("不支持您配置的编码格式:[%s]", encoding), e);
        }
    }

    // only support compress types
    String compress = writerConfiguration.getString(Key.COMPRESS);
    if (StringUtils.isBlank(compress)) {
        writerConfiguration.set(Key.COMPRESS, null);
    } else {
        Set<String> supportedCompress = Sets.newHashSet("gzip", "bzip2");
        if (!supportedCompress.contains(compress.toLowerCase().trim())) {
            String message = String.format(
                    "仅支持 [%s] 文件压缩格式 , 不支持您配置的文件压缩格式: [%s]",
                    StringUtils.join(supportedCompress, ","));
            throw DataXException.asDataXException(
                    UnstructuredStorageWriterErrorCode.ILLEGAL_VALUE,
                    String.format(message, compress));
        }
    }

    // fieldDelimiter check
    String delimiterInStr = writerConfiguration
            .getString(Key.FIELD_DELIMITER);
    // warn: if have, length must be one
    if (null != delimiterInStr && 1 != delimiterInStr.length()) {
        throw DataXException.asDataXException(
                UnstructuredStorageWriterErrorCode.ILLEGAL_VALUE,
                String.format("仅仅支持单字符切分, 您配置的切分为 : [%s]", delimiterInStr));
    }
    if (null == delimiterInStr) {
        LOG.warn(String.format("您没有配置列分隔符, 使用默认值[%s]",
                Constant.DEFAULT_FIELD_DELIMITER));
        writerConfiguration.set(Key.FIELD_DELIMITER,
                Constant.DEFAULT_FIELD_DELIMITER);
    }

    // fileFormat check
    String fileFormat = writerConfiguration.getString(Key.FILE_FORMAT,
            Constant.FILE_FORMAT_TEXT);
    if (!Constant.FILE_FORMAT_CSV.equals(fileFormat)
            && !Constant.FILE_FORMAT_TEXT.equals(fileFormat)) {
        throw DataXException.asDataXException(
                UnstructuredStorageWriterErrorCode.ILLEGAL_VALUE,
                String.format("您配置的fileFormat [%s]错误, 支持csv, plainText两种.",
                        fileFormat));
    }
}
 
Example 3
Source File: UnstructuredStorageReaderUtil.java    From DataLink with Apache License 2.0 4 votes vote down vote up
/**
    * check parameter:encoding, compress, filedDelimiter
    * */
public static void validateParameter(Configuration readerConfiguration) {

	// encoding check
	 String encoding = readerConfiguration.getUnnecessaryValue(
				com.ucar.datalink.flinker.plugin.unstructuredstorage.reader.Key.ENCODING,
				com.ucar.datalink.flinker.plugin.unstructuredstorage.reader.Constant.DEFAULT_ENCODING,null);
	 try {
            encoding = encoding.trim();
            readerConfiguration.set(Key.ENCODING, encoding);
            Charsets.toCharset(encoding);
        } catch (UnsupportedCharsetException uce) {
			throw DataXException.asDataXException(UnstructuredStorageReaderErrorCode.ILLEGAL_VALUE,
					String.format("不支持您配置的编码格式 : [%s]", encoding), uce);
	} catch (Exception e) {
			throw DataXException.asDataXException(UnstructuredStorageReaderErrorCode.CONFIG_INVALID_EXCEPTION,
					String.format("编码配置异常, 请联系我们: %s", e.getMessage()), e);
	}
	 
	 //only support compress types
	 String compress =readerConfiguration
				.getUnnecessaryValue(com.ucar.datalink.flinker.plugin.unstructuredstorage.reader.Key.COMPRESS,null,null);
		if(compress != null){
			compress = compress.toLowerCase().trim();
			boolean compressTag = "gzip".equals(compress) || "bzip2".equals(compress);
			if (!compressTag) {
				throw DataXException.asDataXException(UnstructuredStorageReaderErrorCode.ILLEGAL_VALUE,
						String.format("仅支持 gzip, bzip2 文件压缩格式 , 不支持您配置的文件压缩格式: [%s]", compress));
			}
		}		
		readerConfiguration.set(com.ucar.datalink.flinker.plugin.unstructuredstorage.reader.Key.COMPRESS, compress);
		
		//fieldDelimiter check
		String delimiterInStr = readerConfiguration.getString(com.ucar.datalink.flinker.plugin.unstructuredstorage.reader.Key.FIELD_DELIMITER,null);
		if(null == delimiterInStr){
			throw DataXException.asDataXException(UnstructuredStorageReaderErrorCode.REQUIRED_VALUE,
					String.format("您提供配置文件有误,[%s]是必填参数.",
							com.ucar.datalink.flinker.plugin.unstructuredstorage.reader.Key.FIELD_DELIMITER));
		}else if(1 != delimiterInStr.length()){
			// warn: if have, length must be one
			throw DataXException.asDataXException(UnstructuredStorageReaderErrorCode.ILLEGAL_VALUE,
					String.format("仅仅支持单字符切分, 您配置的切分为 : [%s]", delimiterInStr));
		}

		// column: 1. index type 2.value type 3.when type is Date, may have
		// format
		List<Configuration> columns = readerConfiguration
				.getListConfiguration(com.ucar.datalink.flinker.plugin.unstructuredstorage.reader.Key.COLUMN);
		if (null == columns || columns.size() == 0) {
			throw DataXException.asDataXException(UnstructuredStorageReaderErrorCode.REQUIRED_VALUE, "您需要指定 columns");
		}
		// handle ["*"]
		if (null != columns && 1 == columns.size()) {
			String columnsInStr = columns.get(0).toString();
			if ("\"*\"".equals(columnsInStr) || "'*'".equals(columnsInStr)) {
				readerConfiguration.set(com.ucar.datalink.flinker.plugin.unstructuredstorage.reader.Key.COLUMN, null);
				columns = null;
			}
		}

		if (null != columns && columns.size() != 0) {
			for (Configuration eachColumnConf : columns) {
				eachColumnConf.getNecessaryValue(com.ucar.datalink.flinker.plugin.unstructuredstorage.reader.Key.TYPE,
						UnstructuredStorageReaderErrorCode.REQUIRED_VALUE);
				Integer columnIndex = eachColumnConf
						.getInt(com.ucar.datalink.flinker.plugin.unstructuredstorage.reader.Key.INDEX);
				String columnValue = eachColumnConf
						.getString(com.ucar.datalink.flinker.plugin.unstructuredstorage.reader.Key.VALUE);

				if (null == columnIndex && null == columnValue) {
					throw DataXException.asDataXException(UnstructuredStorageReaderErrorCode.NO_INDEX_VALUE,
							"由于您配置了type, 则至少需要配置 index 或 value");
				}

				if (null != columnIndex && null != columnValue) {
					throw DataXException.asDataXException(UnstructuredStorageReaderErrorCode.MIXED_INDEX_VALUE,
							"您混合配置了index, value, 每一列同时仅能选择其中一种");
				}
				if (null != columnIndex && columnIndex < 0) {
					throw DataXException.asDataXException(UnstructuredStorageReaderErrorCode.ILLEGAL_VALUE,
							String.format("index需要大于等于0, 您配置的index为[%s]", columnIndex));
				}
			}
		}

}
 
Example 4
Source File: ReversedLinesFileReader.java    From aion-germany with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a ReversedLinesFileReader with the given block size and encoding.
 *
 * @param file
 *            the file to be read
 * @param blockSize
 *            size of the internal buffer (for ideal performance this should
 *            match with the block size of the underlying file system).
 * @param encoding
 *            the encoding of the file
 * @throws IOException  if an I/O error occurs
 * @since 2.3
 */
public ReversedLinesFileReader(final File file, final int blockSize, final Charset encoding) throws IOException {
    this.blockSize = blockSize;
    this.encoding = encoding;

    randomAccessFile = new RandomAccessFile(file, "r");
    totalByteLength = randomAccessFile.length();
    int lastBlockLength = (int) (totalByteLength % blockSize);
    if (lastBlockLength > 0) {
        totalBlockCount = totalByteLength / blockSize + 1;
    } else {
        totalBlockCount = totalByteLength / blockSize;
        if (totalByteLength > 0) {
            lastBlockLength = blockSize;
        }
    }
    currentFilePart = new FilePart(totalBlockCount, lastBlockLength, null);

    // --- check & prepare encoding ---
    Charset charset = Charsets.toCharset(encoding);
    CharsetEncoder charsetEncoder = charset.newEncoder();
    float maxBytesPerChar = charsetEncoder.maxBytesPerChar();
    if(maxBytesPerChar==1f) {
        // all one byte encodings are no problem
        byteDecrement = 1;
    } else if(charset == Charset.forName("UTF-8")) {
        // UTF-8 works fine out of the box, for multibyte sequences a second UTF-8 byte can never be a newline byte
        // http://en.wikipedia.org/wiki/UTF-8
        byteDecrement = 1;
    } else if(charset == Charset.forName("Shift_JIS")) {
        // Same as for UTF-8
        // http://www.herongyang.com/Unicode/JIS-Shift-JIS-Encoding.html
        byteDecrement = 1;
    } else if(charset == Charset.forName("UTF-16BE") || charset == Charset.forName("UTF-16LE")) {
        // UTF-16 new line sequences are not allowed as second tuple of four byte sequences,
        // however byte order has to be specified
        byteDecrement = 2;
    } else if(charset == Charset.forName("UTF-16")) {
        throw new UnsupportedEncodingException(
                "For UTF-16, you need to specify the byte order (use UTF-16BE or UTF-16LE)");
    } else {
        throw new UnsupportedEncodingException(
                "Encoding "+encoding+" is not supported yet (feel free to submit a patch)");
    }
    // NOTE: The new line sequences are matched in the order given, so it is important that \r\n is BEFORE \n
    newLineSequences = new byte[][] { "\r\n".getBytes(encoding), "\n".getBytes(encoding), "\r".getBytes(encoding) };

    avoidNewlineSplitBufferSize = newLineSequences[0].length;
}
 
Example 5
Source File: ReversedLinesFileReader.java    From background-geolocation-android with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a ReversedLinesFileReader with the given block size and encoding.
 *
 * @param file
 *            the file to be read
 * @param blockSize
 *            size of the internal buffer (for ideal performance this should
 *            match with the block size of the underlying file system).
 * @param encoding
 *            the encoding of the file
 * @throws IOException  if an I/O error occurs
 * @since 2.3
 */
public ReversedLinesFileReader(final File file, final int blockSize, final Charset encoding) throws IOException {
    this.blockSize = blockSize;
    this.encoding = encoding;

    randomAccessFile = new RandomAccessFile(file, "r");
    totalByteLength = randomAccessFile.length();
    int lastBlockLength = (int) (totalByteLength % blockSize);
    if (lastBlockLength > 0) {
        totalBlockCount = totalByteLength / blockSize + 1;
    } else {
        totalBlockCount = totalByteLength / blockSize;
        if (totalByteLength > 0) {
            lastBlockLength = blockSize;
        }
    }
    currentFilePart = new FilePart(totalBlockCount, lastBlockLength, null);

    // --- check & prepare encoding ---
    Charset charset = Charsets.toCharset(encoding);
    CharsetEncoder charsetEncoder = charset.newEncoder();
    float maxBytesPerChar = charsetEncoder.maxBytesPerChar();
    if(maxBytesPerChar==1f) {
        // all one byte encodings are no problem
        byteDecrement = 1;
    } else if(charset == Charset.forName("UTF-8")) {
        // UTF-8 works fine out of the box, for multibyte sequences a second UTF-8 byte can never be a newline byte
        // http://en.wikipedia.org/wiki/UTF-8
        byteDecrement = 1;
    } else if(charset == Charset.forName("Shift_JIS")) {
        // Same as for UTF-8
        // http://www.herongyang.com/Unicode/JIS-Shift-JIS-Encoding.html
        byteDecrement = 1;
    } else if(charset == Charset.forName("UTF-16BE") || charset == Charset.forName("UTF-16LE")) {
        // UTF-16 new line sequences are not allowed as second tuple of four byte sequences,
        // however byte order has to be specified
        byteDecrement = 2;
    } else if(charset == Charset.forName("UTF-16")) {
        throw new UnsupportedEncodingException(
                "For UTF-16, you need to specify the byte order (use UTF-16BE or UTF-16LE)");
    } else {
        throw new UnsupportedEncodingException(
                "Encoding "+encoding+" is not supported yet (feel free to submit a patch)");
    }
    // NOTE: The new line sequences are matched in the order given, so it is important that \r\n is BEFORE \n
    newLineSequences = new byte[][] { "\r\n".getBytes(encoding), "\n".getBytes(encoding), "\r".getBytes(encoding) };

    avoidNewlineSplitBufferSize = newLineSequences[0].length;
}
 
Example 6
Source File: ReversedLinesFileReader.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a ReversedLinesFileReader with the given block size and encoding.
 *
 * @param file
 *            the file to be read
 * @param blockSize
 *            size of the internal buffer (for ideal performance this should
 *            match with the block size of the underlying file system).
 * @param encoding
 *            the encoding of the file
 * @throws IOException  if an I/O error occurs
 * @since 2.3
 */
@SuppressWarnings("deprecation") // unavoidable until Java 7
public ReversedLinesFileReader(final File file, final int blockSize, final Charset encoding) throws IOException {
    this.blockSize = blockSize;
    this.encoding = encoding;

    // --- check & prepare encoding ---
    final Charset charset = Charsets.toCharset(encoding);
    final CharsetEncoder charsetEncoder = charset.newEncoder();
    final float maxBytesPerChar = charsetEncoder.maxBytesPerChar();
    if (maxBytesPerChar == 1f) {
        // all one byte encodings are no problem
        byteDecrement = 1;
    } else if (charset == Charsets.UTF_8) {
        // UTF-8 works fine out of the box, for multibyte sequences a second UTF-8 byte can never be a newline byte
        // http://en.wikipedia.org/wiki/UTF-8
        byteDecrement = 1;
    } else if(charset == Charset.forName("Shift_JIS") || // Same as for UTF-8
            // http://www.herongyang.com/Unicode/JIS-Shift-JIS-Encoding.html
            charset == Charset.forName("windows-31j") || // Windows code page 932 (Japanese)
            charset == Charset.forName("x-windows-949") || // Windows code page 949 (Korean)
            charset == Charset.forName("gbk") || // Windows code page 936 (Simplified Chinese)
            charset == Charset.forName("x-windows-950")) { // Windows code page 950 (Traditional Chinese)
        byteDecrement = 1;
    } else if (charset == Charsets.UTF_16BE || charset == Charsets.UTF_16LE) {
        // UTF-16 new line sequences are not allowed as second tuple of four byte sequences,
        // however byte order has to be specified
        byteDecrement = 2;
    } else if (charset == Charsets.UTF_16) {
        throw new UnsupportedEncodingException("For UTF-16, you need to specify the byte order (use UTF-16BE or " +
                "UTF-16LE)");
    } else {
        throw new UnsupportedEncodingException("Encoding " + encoding + " is not supported yet (feel free to " +
                "submit a patch)");
    }

    // NOTE: The new line sequences are matched in the order given, so it is important that \r\n is BEFORE \n
    newLineSequences = new byte[][] { "\r\n".getBytes(encoding), "\n".getBytes(encoding), "\r".getBytes(encoding) };

    avoidNewlineSplitBufferSize = newLineSequences[0].length;

    // Open file
    randomAccessFile = new RandomAccessFile(file, "r");
    totalByteLength = randomAccessFile.length();
    int lastBlockLength = (int) (totalByteLength % blockSize);
    if (lastBlockLength > 0) {
        totalBlockCount = totalByteLength / blockSize + 1;
    } else {
        totalBlockCount = totalByteLength / blockSize;
        if (totalByteLength > 0) {
            lastBlockLength = blockSize;
        }
    }
    currentFilePart = new FilePart(totalBlockCount, lastBlockLength, null);

}
 
Example 7
Source File: SplunkLogServiceMonitorRetriever.java    From Thunder with Apache License 2.0 4 votes vote down vote up
public List<MonitorStat> retrieve(String traceId, Map<String, Object> conditions, String encoding) throws Exception {
    if (StringUtils.isEmpty(traceId)) {
        throw new MonitorException("Trace ID is null");
    }

    if (service == null) {
        throw new MonitorException("Splunk service is null");
    }

    String sourceType = properties.getString(ThunderConstant.NAMESPACE_ELEMENT_NAME);
    int maximumTime = properties.getInteger(ThunderConstant.SPLUNK_MAXIMUM_TIME_ATTRIBUTE_NAME);
    String earliestTime = null;
    String latestTime = null;
    if (MapUtils.isNotEmpty(conditions)) {
        Object sourceTypeObject = conditions.get(ThunderConstant.SPLUNK_SOURCE_TYPE_ATTRIBUTE_NAME);
        if (sourceTypeObject != null) {
            sourceType = sourceTypeObject.toString();
        }

        Object maximumTimeObject = conditions.get(ThunderConstant.SPLUNK_MAXIMUM_TIME_ATTRIBUTE_NAME);
        if (maximumTimeObject != null) {
            maximumTime = (Integer) maximumTimeObject;
        }

        Object earliestTimeObject = conditions.get(ThunderConstant.SPLUNK_EARLIEST_TIME_ATTRIBUTE_NAME);
        if (earliestTimeObject != null) {
            earliestTime = new SimpleDateFormat(DATE_FORMAT_SPLUNK).format((Date) earliestTimeObject);
        }

        Object latestTimeObject = conditions.get(ThunderConstant.SPLUNK_LATEST_TIME_ATTRIBUTE_NAME);
        if (latestTimeObject != null) {
            latestTime = new SimpleDateFormat(DATE_FORMAT_SPLUNK).format((Date) latestTimeObject);
        }
    }

    JobExportArgs exportArgs = new JobExportArgs();
    exportArgs.setOutputMode(JobExportArgs.OutputMode.JSON);
    exportArgs.setMaximumTime(maximumTime);
    if (StringUtils.isNotEmpty(earliestTime)) {
        exportArgs.setEarliestTime(earliestTime);
    }
    if (StringUtils.isNotEmpty(latestTime)) {
        exportArgs.setLatestTime(latestTime);
    }

    InputStream inputStream = service.export("search sourcetype=\"" + sourceType + "\" " + ThunderConstant.TRACE_ID + "=\"" + traceId + "\"", exportArgs);
    if (inputStream == null) {
        throw new MonitorException("Input stream is null");
    }

    List<MonitorStat> monitorStatList = new ArrayList<MonitorStat>();

    String key = "{\"" + ThunderConstant.TRACE_ID + "\":\"" + traceId + "\"";

    InputStreamReader inputStreamReader = new InputStreamReader(inputStream, Charsets.toCharset(encoding));
    BufferedReader bufferedReader = IOUtils.toBufferedReader(inputStreamReader);
    String line = bufferedReader.readLine();
    while (line != null) {
        line = line.replace("\\\"", "\"");
        if (line.contains(key)) {
            line = line.substring(line.indexOf(key) + 1);
            line = line.substring(0, line.indexOf("}"));
            line = "{" + line + "}";
            try {
                MonitorStat monitorStat = create(line);
                String exception = monitorStat.getException();
                if (StringUtils.isNotEmpty(exception)) {
                    exception = exception.replace("\\r\\n\\t", "\r\n\t").replace("\\r\\n", "\r\n");
                    monitorStat.setException(exception);
                }
                monitorStatList.add(monitorStat);
            } catch (Exception e) {
                LOG.error("Create MonitorStat failed", e);
            }
        }
        line = bufferedReader.readLine();
    }

    sort(monitorStatList);

    IOUtils.closeQuietly(bufferedReader);
    IOUtils.closeQuietly(inputStreamReader);
    IOUtils.closeQuietly(inputStream);

    return monitorStatList;
}
 
Example 8
Source File: HtsgetReader.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Object doWork() {
    // construct request from command line args and convert to URI
    final HtsgetRequestBuilder req = new HtsgetRequestBuilder(endpoint, id)
        .withFormat(format)
        .withDataClass(dataClass)
        .withInterval(interval)
        .withFields(fields)
        .withTags(tags)
        .withNotags(notags);
    final URI reqURI = req.toURI();

    final HttpGet getReq = new HttpGet(reqURI);
    try (final CloseableHttpResponse resp = this.client.execute(getReq)) {
        // get content of response
        final HttpEntity entity = resp.getEntity();
        final Header encodingHeader = entity.getContentEncoding();
        final Charset encoding = encodingHeader == null 
            ? StandardCharsets.UTF_8
            : Charsets.toCharset(encodingHeader.getValue());
        final String jsonBody = EntityUtils.toString(entity, encoding);

        final ObjectMapper mapper = this.getObjectMapper();

        if (resp.getStatusLine() == null) {
            throw new UserException("htsget server response did not contain status line");
        }
        final int statusCode = resp.getStatusLine().getStatusCode();
        if (400 <= statusCode && statusCode < 500) {
            final HtsgetErrorResponse err = mapper.readValue(jsonBody, HtsgetErrorResponse.class);
            throw new UserException("Invalid request, received error code: " + statusCode + ", error type: "
                    + err.getError() + ", message: " + err.getMessage());
        } else if (statusCode == 200) {
            final HtsgetResponse response = mapper.readValue(jsonBody, HtsgetResponse.class);

            if (this.readerThreads > 1) {
                this.getDataParallel(response);
            } else {
                this.getData(response);
            }

            logger.info("Successfully wrote to: " + outputFile);

            if (checkMd5) {
                this.checkMd5(response);
            }
        } else {
            throw new UserException("Unrecognized status code: " + statusCode);
        }
    } catch (final IOException e) {
        throw new UserException("IOException during htsget download", e);
    }
    return null;
}
 
Example 9
Source File: LockableFileWriter.java    From aion-germany with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs a LockableFileWriter with a file encoding.
 *
 * @param file  the file to write to, not null
 * @param encoding  the encoding to use, null means platform default
 * @param append  true if content should be appended, false to overwrite
 * @param lockDir  the directory in which the lock file should be held
 * @throws NullPointerException if the file is null
 * @throws IOException in case of an I/O error
 * @throws UnsupportedCharsetException
 *             thrown instead of {@link UnsupportedEncodingException} in version 2.2 if the encoding is not
 *             supported.
 */
public LockableFileWriter(File file, String encoding, boolean append,
        String lockDir) throws IOException {
    this(file, Charsets.toCharset(encoding), append, lockDir);
}
 
Example 10
Source File: ReversedLinesFileReader.java    From aion-germany with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Creates a ReversedLinesFileReader with the given block size and encoding.
 *
 * @param file
 *            the file to be read
 * @param blockSize
 *            size of the internal buffer (for ideal performance this should
 *            match with the block size of the underlying file system).
 * @param encoding
 *            the encoding of the file
 * @throws IOException  if an I/O error occurs
 * @throws UnsupportedCharsetException
 *             thrown instead of {@link UnsupportedEncodingException} in version 2.2 if the encoding is not
 *             supported.
 */
public ReversedLinesFileReader(final File file, final int blockSize, final String encoding) throws IOException {
    this(file, blockSize, Charsets.toCharset(encoding));
}
 
Example 11
Source File: ReversedLinesFileReader.java    From background-geolocation-android with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a ReversedLinesFileReader with the given block size and encoding.
 *
 * @param file
 *            the file to be read
 * @param blockSize
 *            size of the internal buffer (for ideal performance this should
 *            match with the block size of the underlying file system).
 * @param encoding
 *            the encoding of the file
 * @throws IOException  if an I/O error occurs
 * @throws UnsupportedCharsetException
 *             thrown instead of {@link UnsupportedEncodingException} in version 2.2 if the encoding is not
 *             supported.
 */
public ReversedLinesFileReader(final File file, final int blockSize, final String encoding) throws IOException {
    this(file, blockSize, Charsets.toCharset(encoding));
}
 
Example 12
Source File: LockableFileWriter.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructs a LockableFileWriter with a file encoding.
 *
 * @param file  the file to write to, not null
 * @param encoding  the encoding to use, null means platform default
 * @param append  true if content should be appended, false to overwrite
 * @param lockDir  the directory in which the lock file should be held
 * @throws NullPointerException if the file is null
 * @throws IOException in case of an I/O error
 * @throws java.nio.charset.UnsupportedCharsetException
 *             thrown instead of {@link java.io.UnsupportedEncodingException} in version 2.2 if the encoding is not
 *             supported.
 */
public LockableFileWriter(final File file, final String encoding, final boolean append,
        final String lockDir) throws IOException {
    this(file, Charsets.toCharset(encoding), append, lockDir);
}
 
Example 13
Source File: ReversedLinesFileReader.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Creates a ReversedLinesFileReader with the given block size and encoding.
 *
 * @param file
 *            the file to be read
 * @param blockSize
 *            size of the internal buffer (for ideal performance this should
 *            match with the block size of the underlying file system).
 * @param encoding
 *            the encoding of the file
 * @throws IOException  if an I/O error occurs
 * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link UnsupportedEncodingException} in
 * version 2.2 if the encoding is not supported.
 */
public ReversedLinesFileReader(final File file, final int blockSize, final String encoding) throws IOException {
    this(file, blockSize, Charsets.toCharset(encoding));
}