Java Code Examples for org.apache.commons.lang.StringUtils.repeat()

The following are Jave code examples for showing how to use repeat() of the org.apache.commons.lang.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: circus-train   File: PartitionedTablePathResolver.java   View Source Code Vote up 7 votes
PartitionedTablePathResolver(IMetaStoreClient metastore, Table table)
    throws NoSuchObjectException, MetaException, TException {
  this.metastore = metastore;
  this.table = table;
  LOG.debug("Table '{}' is partitioned", Warehouse.getQualifiedName(table));
  tableBaseLocation = locationAsPath(table);
  List<Partition> onePartition = metastore.listPartitions(table.getDbName(), table.getTableName(), (short) 1);
  if (onePartition.isEmpty()) {
    LOG.warn("Table '{}' has no partitions, perhaps you can simply delete: {}.", Warehouse.getQualifiedName(table),
        tableBaseLocation);
    throw new ConfigurationException();
  }
  Path partitionLocation = locationAsPath(onePartition.get(0));
  int branches = partitionLocation.depth() - tableBaseLocation.depth();
  String globSuffix = StringUtils.repeat("*", "/", branches);
  globPath = new Path(tableBaseLocation, globSuffix);
}
 
Example 2
Project: hadoop-oss   File: TestProtoBufRpc.java   View Source Code Vote up 6 votes
@Test(timeout=6000)
public void testExtraLongRpc() throws Exception {
  TestRpcService2 client = getClient2();
  final String shortString = StringUtils.repeat("X", 4);
  // short message goes through
  EchoResponseProto echoResponse = client.echo2(null,
      newEchoRequest(shortString));
  Assert.assertEquals(shortString, echoResponse.getMessage());
  
  final String longString = StringUtils.repeat("X", 4096);
  try {
    client.echo2(null, newEchoRequest(longString));
    Assert.fail("expected extra-long RPC to fail");
  } catch (ServiceException se) {
    // expected
  }
}
 
Example 3
Project: osc-core   File: ServiceFunctionChainRequestValidatorTest.java   View Source Code Vote up 6 votes
@Test
public void testValidate_WithInvalidNameLenghtMax_ThrowsVmidcBrokerValidationException() throws Exception {

	AddOrUpdateServiceFunctionChainRequest request = new AddOrUpdateServiceFunctionChainRequest();
	BaseDto dto = new BaseDto();
	String name = StringUtils.repeat("s", 15);
	request.setName(name);
	dto.setParentId(1L);
	request.setDto(dto);
	// Arrange.
	this.exception.expect(VmidcBrokerValidationException.class);
	this.exception.expectMessage("Invalid Service Function Name: " + request.getName()
	+ "SFC name must not exceed 13 characters, must start with a letter, and can only contain numbers, letters and dash(-).");

	// Act.
	this.validator.validate(request);
}
 
Example 4
Project: hadoop   File: TestProtoBufRpc.java   View Source Code Vote up 6 votes
@Test(timeout=6000)
public void testExtraLongRpc() throws Exception {
  TestRpcService2 client = getClient2();
  final String shortString = StringUtils.repeat("X", 4);
  EchoRequestProto echoRequest = EchoRequestProto.newBuilder()
      .setMessage(shortString).build();
  // short message goes through
  EchoResponseProto echoResponse = client.echo2(null, echoRequest);
  Assert.assertEquals(shortString, echoResponse.getMessage());
  
  final String longString = StringUtils.repeat("X", 4096);
  echoRequest = EchoRequestProto.newBuilder()
      .setMessage(longString).build();
  try {
    echoResponse = client.echo2(null, echoRequest);
    Assert.fail("expected extra-long RPC to fail");
  } catch (ServiceException se) {
    // expected
  }
}
 
Example 5
Project: personium-core   File: BoxCrudTest.java   View Source Code Vote up 6 votes
/**
 * BOX新規登録時にSchemaに1024文字を指定して場合_201になることを確認.
 */
@Test
public void BOX新規登録時にSchemaに1024文字を指定して場合_201になることを確認() {
    PersoniumRequest req = PersoniumRequest.post(UrlUtils.cellCtl(CELL_NAME, ENTITY_TYPE_BOX));
    String schema = "http://" + StringUtils.repeat("x", 1012) + ".com/";
    String[] key = {"Name", "Schema" };
    String[] value = {"testBox", schema };
    req.header(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN).addJsonBody(key, value);
    try {
        PersoniumResponse res = request(req);

        // 400になることを確認
        assertEquals(HttpStatus.SC_CREATED, res.getStatusCode());
    } finally {
        deleteBoxRequest("testBox").returns();
    }
}
 
Example 6
Project: personium-core   File: BoxCrudTest.java   View Source Code Vote up 5 votes
/**
 * BOX新規登録時にSchemaに1025文字を指定して場合_400になることを確認.
 */
@Test
public void BOX新規登録時にSchemaに1025文字を指定して場合_400になることを確認() {
    PersoniumRequest req = PersoniumRequest.post(UrlUtils.cellCtl(CELL_NAME, ENTITY_TYPE_BOX));
    String schema = "http://" + StringUtils.repeat("x", 1013) + ".com/";
    String[] key = {"Name", "Schema" };
    String[] value = {"testBox", schema };
    req.header(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN).addJsonBody(key, value);
    PersoniumResponse res = request(req);

    // 400になることを確認
    assertEquals(HttpStatus.SC_BAD_REQUEST, res.getStatusCode());
}
 
Example 7
Project: personium-core   File: ExtCellUpdateTest.java   View Source Code Vote up 5 votes
/**
 * Urlが1024文字の場合正常に作成されること.
 */
@Test
public final void Urlが1024文字の場合正常に作成されること() {
    String newCellUrl = "http://localhost:8080/personium-core/testcell1" + StringUtils.repeat("a", 977) + "/";

    try {
        ExtCellUtils.create(token, cellName, extCellUrl, HttpStatus.SC_CREATED);
        ExtCellUtils.update(token, cellName, extCellUrl, newCellUrl, HttpStatus.SC_NO_CONTENT);
    } finally {
        ExtCellUtils.delete(token, cellName, newCellUrl, -1);
    }
}
 
Example 8
Project: personium-core   File: ExtCellUpdateTest.java   View Source Code Vote up 5 votes
/**
 * Urlが1025文字以上の場合400エラーを返却すること.
 */
@Test
public final void Urlが1025文字以上の場合400エラーを返却すること() {
    String newCellUrl = "http://localhost:8080/personium-core/testcell1" + StringUtils.repeat("a", 978) + "/";

    try {
        ExtCellUtils.create(token, cellName, extCellUrl, HttpStatus.SC_CREATED);
        ExtCellUtils.update(token, cellName, extCellUrl, newCellUrl, HttpStatus.SC_BAD_REQUEST);
    } finally {
        ExtCellUtils.delete(token, cellName, extCellUrl, -1);
    }
}
 
Example 9
Project: personium-core   File: ExtCellCreateTest.java   View Source Code Vote up 5 votes
/**
 * Urlが1024文字の場合正常に作成されること.
 */
@Test
public final void Urlが1024文字の場合正常に作成されること() {
    String extCellUrl = "http://localhost:8080/personium-core/testcell1"
            + StringUtils.repeat("a", 977) + TRAILING_SLASH;

    try {
        ExtCellUtils.create(token, cellName, extCellUrl, HttpStatus.SC_CREATED);
    } finally {
        ExtCellUtils.delete(token, cellName, extCellUrl, -1);
    }
}
 
Example 10
Project: personium-core   File: ExtCellCreateTest.java   View Source Code Vote up 5 votes
/**
 * Urlが1025文字以上の場合400エラーを返却すること.
 */
@Test
public final void Urlが1025文字以上の場合400エラーを返却すること() {
    String extCellUrl = "http://localhost:8080/personium-core/testcell1"
            + StringUtils.repeat("a", 978) + TRAILING_SLASH;
    ExtCellUtils.create(token, cellName, extCellUrl, HttpStatus.SC_BAD_REQUEST);
}
 
Example 11
Project: morf   File: ChangelogStatementConsumer.java   View Source Code Vote up 5 votes
/**
 * Writes one or more lines of text, applying line wrapping.
 */
private void writeWrapped(final String text) {

  // Handle the case of multiple lines
  if (text.contains(SystemUtils.LINE_SEPARATOR)) {
    for (String line : text.split(SystemUtils.LINE_SEPARATOR)) {
      writeWrapped(line);
    }
    return;
  }

  // Write anything below the wrapping limit
  if (text.length() < LINE_LENGTH) {
    outputStream.println(text);
    return;
  }

  // Measure the indent to use on the split lines
  int indent = 0;
  while (indent < text.length() && text.charAt(indent) == ' ') {
    indent++;
  }
  indent += 2;

  // Split the line, preserving the indent on new lines
  final String firstLineIndent = text.substring(0, indent);
  final String lineSeparator = SystemUtils.LINE_SEPARATOR + StringUtils.repeat(" ", indent);
  outputStream.println(firstLineIndent + WordUtils.wrap(text.substring(indent), LINE_LENGTH - indent, lineSeparator, false));
}
 
Example 12
Project: hdfs-shell   File: PathCompleter.java   View Source Code Vote up 4 votes
@SuppressWarnings({"rawtypes", "unchecked"})
private int analyzePossibilities(String buffer, int cursor, List<String> candidates) throws IOException {
    if (cursor == 0) {
        return -1;
    }
    final String[] args = buffer.substring(0, Math.min(cursor, buffer.length())).split(" |,", 1000);
    if (args.length <= 1) {
        return -1;
    }
    String val = args[args.length - 1];
    if ("".equals(val) || " ".equals(val) || ",".equals(val)) {
        val = ".";
    }

    boolean isAbsolute = val.startsWith("/");

    if (val.startsWith("-")) {
        return -1;
    }

    final int found = val.lastIndexOf('/');
    final String core;
    final String rest;
    if (found == -1) {
        //it's relative
        core = contextCommands.getCurrentDir();
        rest = val;
    } else {
        final String firstPart = val.substring(0, found + 1);
        core = (isAbsolute) ? firstPart : new Path(contextCommands.getCurrentDir(), firstPart).toUri().getPath();
        rest = val.length() == 1 ? "" : val.substring(found + 1);
    }

    final FileSystem fs = FileSystem.get(contextCommands.getConfiguration());
    final Path f = new Path(val);

    boolean folderFound = false;
    if (fs.exists(f) && fs.getFileStatus(f).isDirectory() && !val.endsWith("/") && !val.equals(".")) {
        folderFound = true;
    }

    final Path pathCore = new Path(core);
    if (!fs.exists(pathCore)) {
        return -1;
    }

    final String[] suggestions = getSuggestions(rest, fs, pathCore);

    String commonPrefix = StringUtils.getCommonPrefix(suggestions);
    if (StringUtils.isNotEmpty(commonPrefix) && !commonPrefix.equals(rest)) {
        commonPrefix = rest.isEmpty() || rest.equals(".") ? commonPrefix : commonPrefix.substring(rest.length());
        candidates.add(commonPrefix);
        return cursor;
    } else {
        if (suggestions.length > 1) {
            if (StringUtils.isNotEmpty(commonPrefix) && commonPrefix.equals(rest)) { //problem candidatelistcompletionhandler
                for (int i = 0; i < suggestions.length; i++) {
                    suggestions[i] = StringUtils.repeat(" ", i) + suggestions[i];
                }
            }
            candidates.addAll(removeSlash(suggestions));
        } else {
            if (folderFound) {
                candidates.add("/");
                return cursor;
            } else {
                if (suggestions.length > 0) {
                    suggestions[0] = rest.isEmpty() || rest.equals(".") ? suggestions[0] : suggestions[0].substring(rest.length());
                    candidates.addAll(Arrays.asList(suggestions));
                }
            }
        }
    }


    return suggestions.length == 0 ? -1 : cursor;
}
 
Example 13
Project: BUbiNG   File: RandomNamedGraphServer.java   View Source Code Vote up 4 votes
private String paddedByte(final int b, final XoRoShiRo128PlusRandomGenerator random) {
	return padding ? "" + b  : StringUtils.repeat("0", random.nextInt(2)) + b;
}
 
Example 14
Project: lams   File: DurationFormatUtils.java   View Source Code Vote up 2 votes
/**
 * Represents this token as a String.
 *
 * @return String representation of the token
 */
public String toString() {
    return StringUtils.repeat(this.value.toString(), this.count);
}