类org.apache.commons.io.Charsets源码实例Demo

下面列出了怎么用org.apache.commons.io.Charsets的API类实例代码及写法,或者点击链接到github查看源代码。

@Test
public void testFileUploadWithEagerParsingAndNonASCIIFilename() throws Exception {
    DefaultServer.setRootHandler(new EagerFormParsingHandler().setNext(createHandler()));
    TestHttpClient client = new TestHttpClient();
    try {

        HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/path");
        MultipartEntity entity = new MultipartEntity();

        entity.addPart("formValue", new StringBody("myValue", "text/plain", StandardCharsets.UTF_8));

        File uploadfile = new File(MultipartFormDataParserTestCase.class.getResource("uploadfile.txt").getFile());
        FormBodyPart filePart = new FormBodyPart("file", new FileBody(uploadfile, "τεστ", "application/octet-stream", Charsets.UTF_8.toString()));
        filePart.addField("Content-Disposition", "form-data; name=\"file\"; filename*=\"utf-8''%CF%84%CE%B5%CF%83%CF%84.txt\"");
        entity.addPart(filePart);

        post.setEntity(entity);
        HttpResponse result = client.execute(post);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        HttpClientUtils.readResponse(result);


    } finally {
        client.getConnectionManager().shutdown();
    }
}
 
源代码2 项目: herd   文件: DataBridgeManifestReader.java
/**
 * Reads a JSON manifest file into a JSON manifest object.
 *
 * @param jsonManifestFile the JSON manifest file.
 *
 * @return the manifest object.
 * @throws java.io.IOException if any errors were encountered reading the JSON file.
 * @throws IllegalArgumentException if the manifest file has validation errors.
 */
public M readJsonManifest(File jsonManifestFile) throws IOException, IllegalArgumentException
{
    // Verify that the file exists and can be read.
    HerdFileUtils.verifyFileExistsAndReadable(jsonManifestFile);

    // Deserialize the JSON manifest.
    BufferedInputStream buffer = new BufferedInputStream(new FileInputStream(jsonManifestFile));
    BufferedReader reader = new BufferedReader(new InputStreamReader(buffer, Charsets.UTF_8));
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
    objectMapper.setVisibility(PropertyAccessor.GETTER, Visibility.NONE);
    objectMapper.setVisibility(PropertyAccessor.SETTER, Visibility.NONE);
    M manifest = getManifestFromReader(reader, objectMapper);

    // Validate the manifest and return it.
    validateManifest(manifest);
    return manifest;
}
 
源代码3 项目: msf4j   文件: HttpServerTest.java
@Test
public void testUploadReject() throws Exception {
    HttpURLConnection urlConn = request("/test/v1/uploadReject", HttpMethod.POST, true);
    try {
        urlConn.setChunkedStreamingMode(1024);
        urlConn.getOutputStream().write("Rejected Content".getBytes(Charsets.UTF_8));
        try {
            urlConn.getInputStream();
            fail();
        } catch (IOException e) {
            // Expect to get exception since server response with 400. Just drain the error stream.
            IOUtils.toByteArray(urlConn.getErrorStream());
            assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), urlConn.getResponseCode());
        }
    } finally {
        urlConn.disconnect();
    }
}
 
源代码4 项目: vxquery   文件: XmlCollectionWithTagInputFormat.java
public XmlRecordReader(FileSplit split, Configuration conf) throws IOException {
    endTag = ENDING_TAG.getBytes(Charsets.UTF_8);
    startTag = STARTING_TAG.getBytes(Charsets.UTF_8);

    // open the file and seek to the start of the split
    start = split.getStart();
    // set the end of the file
    end = start + split.getLength();
    Path file = split.getPath();
    FileSystem fs = file.getFileSystem(conf);
    FileStatus fStatus = fs.getFileStatus(file);
    blocks = fs.getFileBlockLocations(fStatus, 0, fStatus.getLen());
    // seek the start of file
    fsin = fs.open(split.getPath());
    fsin.seek(start);
}
 
private void processQueue(ProcessSession session) {
    String xml;
    while ((xml = renderedXMLs.peek()) != null) {
        FlowFile flowFile = session.create();
        byte[] xmlBytes = xml.getBytes(Charsets.UTF_8);
        flowFile = session.write(flowFile, out -> out.write(xmlBytes));
        flowFile = session.putAttribute(flowFile, CoreAttributes.MIME_TYPE.key(), APPLICATION_XML);
        session.getProvenanceReporter().receive(flowFile, provenanceUri);
        session.transfer(flowFile, REL_SUCCESS);
        session.commit();
        if (!renderedXMLs.remove(xml) && getLogger().isWarnEnabled()) {
            getLogger().warn(new StringBuilder("Event ")
                    .append(xml)
                    .append(" had already been removed from queue, FlowFile ")
                    .append(flowFile.getAttribute(CoreAttributes.UUID.key()))
                    .append(" possible duplication of data")
                    .toString());
        }
    }
}
 
public static List<WinNT.HANDLE> mockEventHandles(WEvtApi wEvtApi, Kernel32 kernel32, List<String> eventXmls) {
    List<WinNT.HANDLE> eventHandles = new ArrayList<>();
    for (String eventXml : eventXmls) {
        WinNT.HANDLE eventHandle = mock(WinNT.HANDLE.class);
        when(wEvtApi.EvtRender(isNull(WinNT.HANDLE.class), eq(eventHandle), eq(WEvtApi.EvtRenderFlags.EVENT_XML),
                anyInt(), any(Pointer.class), any(Pointer.class), any(Pointer.class))).thenAnswer(invocation -> {
            Object[] arguments = invocation.getArguments();
            Pointer bufferUsed = (Pointer) arguments[5];
            byte[] array = Charsets.UTF_16LE.encode(eventXml).array();
            if (array.length > (int) arguments[3]) {
                when(kernel32.GetLastError()).thenReturn(W32Errors.ERROR_INSUFFICIENT_BUFFER).thenReturn(W32Errors.ERROR_SUCCESS);
            } else {
                ((Pointer) arguments[4]).write(0, array, 0, array.length);
            }
            bufferUsed.setInt(0, array.length);
            return false;
        });
        eventHandles.add(eventHandle);
    }
    return eventHandles;
}
 
源代码7 项目: onos   文件: DhcpTest.java
/**
 * Test option with option length > 128.
 */
@Test
public void longOptionTest() throws Exception {
    byte[] data = Resources.toByteArray(Dhcp6RelayTest.class.getResource(LONG_OPT));
    DHCP dhcp = DHCP.deserializer().deserialize(data, 0, data.length);
    assertEquals(2, dhcp.getOptions().size());
    DhcpOption hostnameOption = dhcp.getOption(DHCP.DHCPOptionCode.OptionCode_HostName);
    DhcpOption endOption = dhcp.getOption(DHCP.DHCPOptionCode.OptionCode_END);
    assertNotNull(hostnameOption);
    assertNotNull(endOption);

    // Host name contains 200 "A"
    StringBuilder hostnameBuilder = new StringBuilder();
    IntStream.range(0, 200).forEach(i -> hostnameBuilder.append("A"));
    String hostname = hostnameBuilder.toString();

    assertEquals((byte) 200, hostnameOption.getLength());
    assertArrayEquals(hostname.getBytes(Charsets.US_ASCII), hostnameOption.getData());
}
 
源代码8 项目: nexus-public   文件: GolangHostedFacetImplTest.java
@Test
public void getList() throws IOException {
  String expected = "v1.0.0\nv1.0.1";
  String name = "module/@v/v1.0.0.list";

  NestedAttributesMap attributesMap = mock(NestedAttributesMap.class);
  when(attributesMap.get("asset_kind")).thenReturn(PACKAGE.name());
  when(asset1.name()).thenReturn("modulename/@v/v1.0.0.zip");
  when(asset1.formatAttributes()).thenReturn(attributesMap);
  when(asset2.name()).thenReturn("modulename/@v/v1.0.1.zip");
  when(asset2.formatAttributes()).thenReturn(attributesMap);

  when(dataAccess.findAssetsForModule(tx, repository, name)).thenReturn(
      ImmutableList.of(asset1, asset2)
  );

  Content content = underTest.getList(name);

  String response = CharStreams.toString(new InputStreamReader(content.openInputStream(), Charsets.UTF_8));

  assertThat(response, is(equalTo(expected)));
}
 
public static List<HyperParameterScopeItem> read(final String configFilePath) {
    final File file = new File(configFilePath);
    List<String> lines;
    try {
        lines = FileUtils.readLines(file, Charsets.UTF_8);
    } catch (final IOException e) {
        throw new IllegalStateException(e);
    }
    final List<HyperParameterScopeItem> result = Lists.newArrayList();
    for (final String line : lines) {
        final String[] segments = StringUtils.split(line, ',');
        final List<String> values = Lists.newArrayList();
        for (int i = 1; i < segments.length; ++i) {
            values.add(segments[i]);
        }
        final HyperParameterScopeItem item = new HyperParameterScopeItem(segments[0], values);
        result.add(item);
    }
    return result;
}
 
源代码10 项目: nifi   文件: AbstractAWSGatewayApiProcessor.java
/**
 * Returns a map of Query Parameter Name to Values
 *
 * @param context ProcessContext
 * @return Map of names and values
 */
protected Map<String, List<String>> getParameters(ProcessContext context) {

    if (!context.getProperty(PROP_QUERY_PARAMS).isSet()) {
        return new HashMap<>();
    }
    final String queryString = context.getProperty(PROP_QUERY_PARAMS)
                                      .evaluateAttributeExpressions().getValue();
    List<NameValuePair> params = URLEncodedUtils
        .parse(queryString, Charsets.toCharset("UTF-8"));

    if (params.isEmpty()) {
        return new HashMap<>();
    }

    Map<String, List<String>> map = new HashMap<>();

    for (NameValuePair nvp : params) {
        if (!map.containsKey(nvp.getName())) {
            map.put(nvp.getName(), new ArrayList<>());
        }
        map.get(nvp.getName()).add(nvp.getValue());
    }
    return map;
}
 
源代码11 项目: hadoop   文件: FSDirMkdirOp.java
/**
 * For a given absolute path, create all ancestors as directories along the
 * path. All ancestors inherit their parent's permission plus an implicit
 * u+wx permission. This is used by create() and addSymlink() for
 * implicitly creating all directories along the path.
 *
 * For example, path="/foo/bar/spam", "/foo" is an existing directory,
 * "/foo/bar" is not existing yet, the function will create directory bar.
 *
 * @return a tuple which contains both the new INodesInPath (with all the
 * existing and newly created directories) and the last component in the
 * relative path. Or return null if there are errors.
 */
static Map.Entry<INodesInPath, String> createAncestorDirectories(
    FSDirectory fsd, INodesInPath iip, PermissionStatus permission)
    throws IOException {
  final String last = new String(iip.getLastLocalName(), Charsets.UTF_8);
  INodesInPath existing = iip.getExistingINodes();
  List<String> children = iip.getPath(existing.length(),
      iip.length() - existing.length());
  int size = children.size();
  if (size > 1) { // otherwise all ancestors have been created
    List<String> directories = children.subList(0, size - 1);
    INode parentINode = existing.getLastINode();
    // Ensure that the user can traversal the path by adding implicit
    // u+wx permission to all ancestor directories
    existing = createChildrenDirectories(fsd, existing, directories,
        addImplicitUwx(parentINode.getPermissionStatus(), permission));
    if (existing == null) {
      return null;
    }
  }
  return new AbstractMap.SimpleImmutableEntry<>(existing, last);
}
 
源代码12 项目: nexus-public   文件: GolangHostedFacetImplTest.java
@Test
public void getInfo() throws IOException {
  DateTime blobCreated = DateTime.now();
  String expected = String.format("{\"Version\":\"v1.0.0\",\"Time\":\"%s\"}", blobCreated.toString());
  when(dataAccess.findAsset(any(), any(), any())).thenReturn(asset1);
  when(asset1.blobCreated()).thenReturn(blobCreated);

  GolangAttributes goAttributes = new GolangAttributes();
  goAttributes.setModule("module");
  goAttributes.setVersion("v1.0.0");

  Content content = underTest.getInfo(MODULE_INFO, goAttributes);
  String response = CharStreams.toString(new InputStreamReader(content.openInputStream(), Charsets.UTF_8));

  assertThat(response, is(equalTo(expected)));
}
 
源代码13 项目: hadoop   文件: TestGetBlockLocations.java
private static FSNamesystem setupFileSystem() throws IOException {
  Configuration conf = new Configuration();
  conf.setLong(DFS_NAMENODE_ACCESSTIME_PRECISION_KEY, 1L);
  FSEditLog editlog = mock(FSEditLog.class);
  FSImage image = mock(FSImage.class);
  when(image.getEditLog()).thenReturn(editlog);
  final FSNamesystem fsn = new FSNamesystem(conf, image, true);

  final FSDirectory fsd = fsn.getFSDirectory();
  INodesInPath iip = fsd.getINodesInPath("/", true);
  PermissionStatus perm = new PermissionStatus(
      "hdfs", "supergroup",
      FsPermission.createImmutable((short) 0x1ff));
  final INodeFile file = new INodeFile(
      MOCK_INODE_ID, FILE_NAME.getBytes(Charsets.UTF_8),
      perm, 1, 1, new BlockInfoContiguous[] {}, (short) 1,
      DFS_BLOCK_SIZE_DEFAULT);
  fsn.getFSDirectory().addINode(iip, file);
  return fsn;
}
 
源代码14 项目: big-c   文件: FSDirMkdirOp.java
/**
 * For a given absolute path, create all ancestors as directories along the
 * path. All ancestors inherit their parent's permission plus an implicit
 * u+wx permission. This is used by create() and addSymlink() for
 * implicitly creating all directories along the path.
 *
 * For example, path="/foo/bar/spam", "/foo" is an existing directory,
 * "/foo/bar" is not existing yet, the function will create directory bar.
 *
 * @return a tuple which contains both the new INodesInPath (with all the
 * existing and newly created directories) and the last component in the
 * relative path. Or return null if there are errors.
 */
static Map.Entry<INodesInPath, String> createAncestorDirectories(
    FSDirectory fsd, INodesInPath iip, PermissionStatus permission)
    throws IOException {
  final String last = new String(iip.getLastLocalName(), Charsets.UTF_8);
  INodesInPath existing = iip.getExistingINodes();
  List<String> children = iip.getPath(existing.length(),
      iip.length() - existing.length());
  int size = children.size();
  if (size > 1) { // otherwise all ancestors have been created
    List<String> directories = children.subList(0, size - 1);
    INode parentINode = existing.getLastINode();
    // Ensure that the user can traversal the path by adding implicit
    // u+wx permission to all ancestor directories
    existing = createChildrenDirectories(fsd, existing, directories,
        addImplicitUwx(parentINode.getPermissionStatus(), permission));
    if (existing == null) {
      return null;
    }
  }
  return new AbstractMap.SimpleImmutableEntry<>(existing, last);
}
 
源代码15 项目: zeppelin   文件: JinjaTemplatesTest.java
public String tensorboardJinjaTemplateTest(Boolean dist, Boolean launchMode) throws IOException {
  URL urlTemplate = Resources.getResource(SubmarineJob.SUBMARINE_TENSORBOARD_JINJA);
  String template = Resources.toString(urlTemplate, Charsets.UTF_8);
  Jinjava jinjava = new Jinjava();
  HashMap<String, Object> jinjaParams = initJinjaParams(dist, launchMode);

  String submarineCmd = jinjava.render(template, jinjaParams);
  int pos = submarineCmd.indexOf("\n");
  if (pos == 0) {
    submarineCmd = submarineCmd.replaceFirst("\n", "");
  }
  LOGGER.info("------------------------");
  LOGGER.info(submarineCmd);
  LOGGER.info("------------------------");

  return submarineCmd;
}
 
源代码16 项目: zeppelin   文件: JinjaTemplatesTest.java
public String jobRunJinjaTemplateTest(Boolean dist, Boolean launchMode) throws IOException {
  URL urlTemplate = Resources.getResource(SubmarineJob.SUBMARINE_JOBRUN_TF_JINJA);
  String template = Resources.toString(urlTemplate, Charsets.UTF_8);
  Jinjava jinjava = new Jinjava();
  HashMap<String, Object> jinjaParams = initJinjaParams(dist, launchMode);

  String submarineCmd = jinjava.render(template, jinjaParams);
  int pos = submarineCmd.indexOf("\n");
  if (pos == 0) {
    submarineCmd = submarineCmd.replaceFirst("\n", "");
  }

  LOGGER.info("------------------------");
  LOGGER.info(submarineCmd);
  LOGGER.info("------------------------");

  return submarineCmd;
}
 
源代码17 项目: parallec   文件: SshProviderMockTest.java
@Test
public void executeAndGenResponseThrowsExceptionTest() {

    // ResponseOnSingeReq (Channel channel) {
    ResponseOnSingeRequest sshResponse = new ResponseOnSingeRequest();
    ChannelExec channel = mock(ChannelExec.class);
    sshProvider = new SshProvider(sshMetaKey, hostIpSample);
    String stdoutStr = "Mon Sep 14 21:52:27 UTC 2015";
    InputStream in = new ByteArrayInputStream(
            stdoutStr.getBytes(Charsets.UTF_8));

    try {
        when(channel.getInputStream()).thenReturn(in);
        when(channel.isClosed()).thenReturn(false).thenThrow(
                new RuntimeException("fake exception"));
        sshResponse = sshProvider.executeAndGenResponse(channel);
    } catch (Throwable e) {
        logger.info("expected exception {}", "String", e);
    }

    logger.info(sshResponse.toString());
}
 
源代码18 项目: Nicobar   文件: SingleFileScriptArchiveTest.java
@Test
public void testDefaultModuleSpec() throws Exception {
    URL rootPathUrl = getClass().getClassLoader().getResource(TEST_SCRIPTS_PATH.getResourcePath());
    Path rootPath = Paths.get(rootPathUrl.toURI()).toAbsolutePath();
    Set<String> singleFileScripts = TEST_SCRIPTS_PATH.getContentPaths();
    for (String script: singleFileScripts) {
        Path scriptPath = rootPath.resolve(script);
        SingleFileScriptArchive scriptArchive = new SingleFileScriptArchive.Builder(scriptPath)
            .build();
        String moduleId = script.replaceAll("\\.", "_");
        assertEquals(scriptArchive.getModuleSpec().getModuleId().toString(), moduleId);
        Set<String> archiveEntryNames = scriptArchive.getArchiveEntryNames();
        assertEquals(archiveEntryNames.size(), 1);
        for (String entryName : archiveEntryNames) {
            URL entryUrl = scriptArchive.getEntry(entryName);
            assertNotNull(entryUrl);
            InputStream inputStream = entryUrl.openStream();
            String content = IOUtils.toString(inputStream, Charsets.UTF_8);

            // We have stored the file name as the content of the file
            assertEquals(content, script + "\n");
        }
    }
}
 
源代码19 项目: hadoop   文件: LdapGroupsMapping.java
String extractPassword(String pwFile) {
  if (pwFile.isEmpty()) {
    // If there is no password file defined, we'll assume that we should do
    // an anonymous bind
    return "";
  }

  StringBuilder password = new StringBuilder();
  try (Reader reader = new InputStreamReader(
      new FileInputStream(pwFile), Charsets.UTF_8)) {
    int c = reader.read();
    while (c > -1) {
      password.append((char)c);
      c = reader.read();
    }
    return password.toString().trim();
  } catch (IOException ioe) {
    throw new RuntimeException("Could not read password file: " + pwFile, ioe);
  }
}
 
源代码20 项目: AndServer   文件: Uri.java
private static MultiValueMap<String, String> convertQuery(String query) {
    MultiValueMap<String, String> valueMap = new LinkedMultiValueMap<>();
    if (!StringUtils.isEmpty(query)) {
        if (query.startsWith("?")) query = query.substring(1);

        StringTokenizer tokenizer = new StringTokenizer(query, "&");
        while (tokenizer.hasMoreElements()) {
            String element = tokenizer.nextToken();
            int end = element.indexOf("=");

            if (end > 0 && end < element.length() - 1) {
                String key = element.substring(0, end);
                String value = element.substring(end + 1);
                valueMap.add(key, UrlCoder.urlDecode(value, Charsets.UTF_8));
            }
        }
    }
    return valueMap;
}
 
源代码21 项目: big-c   文件: LdapGroupsMapping.java
String extractPassword(String pwFile) {
  if (pwFile.isEmpty()) {
    // If there is no password file defined, we'll assume that we should do
    // an anonymous bind
    return "";
  }

  StringBuilder password = new StringBuilder();
  try (Reader reader = new InputStreamReader(
      new FileInputStream(pwFile), Charsets.UTF_8)) {
    int c = reader.read();
    while (c > -1) {
      password.append((char)c);
      c = reader.read();
    }
    return password.toString().trim();
  } catch (IOException ioe) {
    throw new RuntimeException("Could not read password file: " + pwFile, ioe);
  }
}
 
源代码22 项目: big-c   文件: Display.java
/**
 * Read a single byte from the stream.
 */
@Override
public int read() throws IOException {
  if (pos < buffer.length) {
    return buffer[pos++];
  }
  if (!fileReader.hasNext()) {
    return -1;
  }
  writer.write(fileReader.next(), encoder);
  encoder.flush();
  if (!fileReader.hasNext()) {
    // Write a new line after the last Avro record.
    output.write(System.getProperty("line.separator")
                     .getBytes(Charsets.UTF_8));
    output.flush();
  }
  pos = 0;
  buffer = output.toByteArray();
  output.reset();
  return read();
}
 
源代码23 项目: carbon-identity   文件: OAuthUtil.java
/**
 * Generates a random number using two UUIDs and HMAC-SHA1
 *
 * @return generated secure random number
 * @throws IdentityOAuthAdminException Invalid Algorithm or Invalid Key
 */
public static String getRandomNumber() throws IdentityOAuthAdminException {
    try {
        String secretKey = UUIDGenerator.generateUUID();
        String baseString = UUIDGenerator.generateUUID();

        SecretKeySpec key = new SecretKeySpec(secretKey.getBytes(Charsets.UTF_8), ALGORITHM);
        Mac mac = Mac.getInstance(ALGORITHM);
        mac.init(key);
        byte[] rawHmac = mac.doFinal(baseString.getBytes(Charsets.UTF_8));
        String random = Base64.encode(rawHmac);
        // Registry doesn't have support for these character.
        random = random.replace("/", "_");
        random = random.replace("=", "a");
        random = random.replace("+", "f");
        return random;
    } catch (Exception e) {
        throw new IdentityOAuthAdminException("Error when generating a random number.", e);
    }
}
 
源代码24 项目: big-c   文件: GangliaContext.java
/**
 * Puts a string into the buffer by first writing the size of the string
 * as an int, followed by the bytes of the string, padded if necessary to
 * a multiple of 4.
 */
protected void xdr_string(String s) {
  byte[] bytes = s.getBytes(Charsets.UTF_8);
  int len = bytes.length;
  xdr_int(len);
  System.arraycopy(bytes, 0, buffer, offset, len);
  offset += len;
  pad();
}
 
源代码25 项目: big-c   文件: JSONProvider.java
@Override
public void writeTo(JSONStreamAware jsonStreamAware, Class<?> aClass, Type type, Annotation[] annotations,
                    MediaType mediaType, MultivaluedMap<String, Object> stringObjectMultivaluedMap,
                    OutputStream outputStream) throws IOException, WebApplicationException {
  Writer writer = new OutputStreamWriter(outputStream, Charsets.UTF_8);
  jsonStreamAware.writeJSONString(writer);
  writer.write(ENTER);
  writer.flush();
}
 
源代码26 项目: kylin-on-parquet-v2   文件: TempMetadataBuilder.java
private Pair<Integer, Integer> grabDefaultEngineTypes(String tempMetadataDir) throws IOException {
    int engineType = -1;
    int storageType = -1;

    List<String> lines = FileUtils.readLines(new File(tempMetadataDir, "kylin.properties"), Charsets.UTF_8);
    for (String l : lines) {
        if (l.startsWith("kylin.engine.default")) {
            engineType = Integer.parseInt(l.substring(l.lastIndexOf('=') + 1).trim());
        }
        if (l.startsWith("kylin.storage.default")) {
            storageType = Integer.parseInt(l.substring(l.lastIndexOf('=') + 1).trim());
        }
    }

    if (debug) {
        logger.info("Grap from kylin.properties, engine type is {}", engineType);
        logger.info("Grap from kylin.properties, storage type is {}", storageType);
    }

    String tmp = System.getProperty("kylin.engine");
    if (!StringUtils.isBlank(tmp)) {
        engineType = Integer.parseInt(tmp.trim());
        if (debug) {
            logger.info("By system property, engine type is {}", engineType);
        }
    }
    tmp = System.getProperty("kylin.storage");
    if (!StringUtils.isBlank(tmp)) {
        storageType = Integer.parseInt(tmp.trim());
        if (debug) {
            logger.info("By system property, storage type is {}", storageType);
        }
    }

    if (engineType < 0 || storageType < 0)
        throw new IllegalStateException();

    return Pair.newPair(engineType, storageType);
}
 
源代码27 项目: freehealth-connector   文件: STSServiceImpl.java
private Document generateToken(String requestTemplate, boolean sign, Credential headerCred, Credential hokCred, SAMLNameIdentifier nameIdentifier, String authmethod, List<SAMLAttribute> attributes, List<SAMLAttributeDesignator> designators, int validity) throws TechnicalConnectorException {
   try {
      String request = ConnectorXmlUtils.flatten(requestTemplate);
      request = this.processDefaultFields(request, validity, nameIdentifier);
      request = this.processHolderOfKeyCredentials(hokCred, request);
      request = StringUtils.replace(request, "${authenticationMethod}", authmethod);
      Element payload = ConnectorXmlUtils.toElement(request.getBytes(Charsets.UTF_8));
      Document doc = payload.getOwnerDocument();
      this.addDesignators(designators, doc);
      this.processAttributes(attributes, doc);
      boolean alwaysSign = Boolean.parseBoolean(ConfigFactory.getConfigValidator().getProperty("be.ehealth.technicalconnector.service.sts.always.sign.inner.request"));
      if (sign && (!headerCred.getCertificate().equals(hokCred.getCertificate()) || alwaysSign)) {
         try {
            String keyinfoType = ConfigFactory.getConfigValidator().getProperty("be.ehealth.technicalconnector.service.sts.keyinfo", "x509");
            if ("publickey".equalsIgnoreCase(keyinfoType)) {
               this.signRequest(doc.getDocumentElement(), hokCred.getPrivateKey(), hokCred.getPublicKey());
            } else {
               this.signRequest(doc.getDocumentElement(), hokCred.getPrivateKey(), hokCred.getCertificate());
            }
         } catch (Exception var15) {
            throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_SIGNATURE, new Object[]{"XML signature error: " + var15.getMessage(), var15});
         }
      }

      return doc;
   } catch (CertificateEncodingException var16) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_CRYPTO, var16, new Object[]{var16.getMessage()});
   }
}
 
源代码28 项目: ignite   文件: InlineIndexColumnTest.java
/** Test utf-8 string cutting. */
@Test
public void testConvert() {
    // 8 bytes total: 1b, 1b, 3b, 3b.
    byte[] bytes = StringInlineIndexColumn.trimUTF8("00\u20ac\u20ac".getBytes(Charsets.UTF_8), 7);
    assertEquals(5, bytes.length);

    String s = new String(bytes);
    assertEquals(3, s.length());

    bytes = StringInlineIndexColumn.trimUTF8("aaaaaa".getBytes(Charsets.UTF_8), 4);
    assertEquals(4, bytes.length);
}
 
源代码29 项目: cs-actions   文件: WSManUtils.java
public static String constructCommand(final WSManRequestInputs wsManRequestInputs, final PSEdition psEdition) {
    final StringBuilder command = new StringBuilder()
            .append(psEdition.getCmd())
            .append(SPACE)
            .append(NON_INTERACTIVE_PARAMETER)
            .append(SPACE);

    if(StringUtils.isNotBlank(wsManRequestInputs.getConfigurationName())) {
        command.append(CONFIGURATION_NAME_PARAMETER)
                .append(SPACE)
                .append(wsManRequestInputs.getConfigurationName())
                .append(SPACE);
    }

    command.append(ENCODED_COMMAND_PARAMETER)
            .append(SPACE);

    if (StringUtilities.isNotBlank(wsManRequestInputs.getModules())) {
        command.append(EncoderDecoder.encodeStringInBase64(
                IMPORT_MODULE_PARAMETER +
                        SPACE +
                        getEscapedModules(wsManRequestInputs) +
                        LF +
                        wsManRequestInputs.getScript(), Charsets.UTF_16LE));
    } else {
        command.append(EncoderDecoder.encodeStringInBase64(wsManRequestInputs.getScript(), Charsets.UTF_16LE));
    }
    return command.toString();
}
 
源代码30 项目: dremio-oss   文件: TestBoundedPivots.java
private static void validateVarCharValues(int blockWidth, VectorPivotDef def, FixedBlockVector block,
    VariableBlockVector varBlock, String[] expected){
  int[] expectNulls = new int[expected.length];
  String[] expectValues = new String[expected.length];
  for(int i =0; i < expected.length; i++){
    String e = expected[i];
    if(e != null){
      expectNulls[i] = 1;
      expectValues[i] = e;
    }
  }
  int[] actualNulls = new int[expectNulls.length];
  String[] actualValues = new String[expectNulls.length];
  long nullBitOffsetA = def.getNullBitOffset();
  final ArrowBuf buf = block.getUnderlying();
  for(int i =0; i < expectNulls.length; i++){
    actualNulls[i] =  (buf.getInt(((i * blockWidth) + def.getNullByteOffset())) >>> nullBitOffsetA) & 1;
    if (actualNulls[i] != 0) {
      int offset = buf.getInt(i * blockWidth + blockWidth - 4);
      int len = varBlock.getUnderlying().getInt(offset + 4);
      byte val[] = new byte[len];
      varBlock.getUnderlying().getBytes(offset + 4 + 4, val, 0, len);
      actualValues[i] = new String(val, Charsets.UTF_8);
    }
  }
  assertArrayEquals(expectNulls, actualNulls);
  assertArrayEquals(expectValues, actualValues);
}
 
 类所在包
 同包方法