List of usage examples for org.apache.commons.lang ArrayUtils add
public static short[] add(short[] array, short element)
Copies the given array and adds the given element at the end of the new array.
From source file:com.dushyant.flume.sink.aws.sqs.BatchSQSMsgSenderTest.java
/** * Tests {@link BatchSQSMsgSender#createBatches(org.apache.flume.Channel)} method. Tests invalid characters not * allowed by the SQS. See [http://docs.aws.amazon * .com/AWSSimpleQueueService/latest/APIReference/API_SendMessageBatch.html] * for list of valid characters allowed by SQS. * <p>//from www . j a va 2 s .c o m * <p> * <pre> * Inputs: * channel = never empty. with messages containing invalid characters. * * Expected Output: * The sink messages should not contain invalid characters * </pre> */ @Test public void testInvalidCharacters() throws Exception { // See // http://stackoverflow.com/questions/16688523/aws-sqs-valid-characters // http://stackoverflow.com/questions/1169754/amazon-sqs-invalid-binary-character-in-message-body // https://forums.aws.amazon.com/thread.jspa?messageID=459090 // http://stackoverflow.com/questions/16329695/invalid-binary-character-when-transmitting-protobuf-net // -messages-over-aws-sqs byte invalidCharByte = 0x1C; String mockMsg = "Test with some invalid chars at the end 0%2F>^F"; byte[] origPayloadWithInvalidChars = ArrayUtils.add(mockMsg.getBytes(), invalidCharByte); BatchSQSMsgSender sqsMsgSender = new BatchSQSMsgSender("https://some-fake/url", "us-east-1", "someAwsAccessKey", "someAwsSecretKey", 1, origPayloadWithInvalidChars.length); Event mockEvent = Mockito.mock(Event.class); when(mockEvent.getBody()).thenReturn(origPayloadWithInvalidChars); Channel mockChannel = Mockito.mock(Channel.class); when(mockChannel.take()).thenReturn(mockEvent); List<SendMessageBatchRequest> batches = sqsMsgSender.createBatches(mockChannel); List<SendMessageBatchRequestEntry> msgEntries = batches.get(0).getEntries(); assertCorrectPayloadInEntries(new String(origPayloadWithInvalidChars).trim().getBytes(), msgEntries); // Make sure that the message being sent by the sink doesn't contain the invalid characters for (SendMessageBatchRequestEntry entry : msgEntries) { Assert.assertNotNull(entry); Assert.assertTrue( ArrayUtils.contains(new String(origPayloadWithInvalidChars).getBytes(), invalidCharByte)); Assert.assertTrue(!ArrayUtils.contains(entry.getMessageBody().getBytes(), invalidCharByte)); } }
From source file:com.logsniffer.app.CoreAppConfig.java
@Bean(name = { BEAN_LOGSNIFFER_PROPS }) @Autowired//from ww w . j a v a2s. c o m public PropertiesFactoryBean logSnifferProperties(final ApplicationContext ctx) throws IOException { if (ctx.getEnvironment().acceptsProfiles("!" + ContextProvider.PROFILE_NONE_QA)) { final File qaFile = File.createTempFile("logsniffer", "qa"); qaFile.delete(); final String qaHomeDir = qaFile.getPath(); logger.info("QA mode active, setting random home directory: {}", qaHomeDir); System.setProperty("logsniffer.home", qaHomeDir); } final PathMatchingResourcePatternResolver pathMatcher = new PathMatchingResourcePatternResolver(); Resource[] classPathProperties = pathMatcher.getResources("classpath*:/config/**/logsniffer-*.properties"); final Resource[] metainfProperties = pathMatcher .getResources("classpath*:/META-INF/**/logsniffer-*.properties"); final PropertiesFactoryBean p = new PropertiesFactoryBean(); for (final Resource r : metainfProperties) { classPathProperties = (Resource[]) ArrayUtils.add(classPathProperties, r); } classPathProperties = (Resource[]) ArrayUtils.add(classPathProperties, new FileSystemResource(System.getProperty("logsniffer.home") + "/" + LOGSNIFFER_PROPERTIES_FILE)); p.setLocations(classPathProperties); p.setProperties(System.getProperties()); p.setLocalOverride(true); p.setIgnoreResourceNotFound(true); return p; }
From source file:at.tuwien.ifs.somtoolbox.input.ESOMFormatInputReader.java
public ESOMFormatInputReader(String weightsFile, String bmFile) throws NumberFormatException, IOException, SOMToolboxException { // FIXME: set topology in the gridTopology field! this.weightsFile = weightsFile; this.bmFile = bmFile; // read the weights file BufferedReader br = FileUtils.openFile("ESOM map file", weightsFile); String line = FileUtils.consumeHeaderComments(br); // first line: size line = line.trim().substring(1).trim(); ySize = Integer.parseInt(line.split(" ")[0]); // first rows xSize = Integer.parseInt(line.split(" ")[1]); // then columns zSize = 1;//from w ww .ja v a 2s . com // second line: dimensionality line = br.readLine(); dim = Integer.parseInt(line.trim().substring(1).trim()); // there might be a third header line, which is undocumented, and contains simply a "1" for each dimension... line = br.readLine(); if (line != null && line.trim().startsWith("%")) { // we just consume this line.. line = br.readLine(); } // subsequent lines: weights unitInfo = new UnitInformation[xSize][ySize][zSize]; int index = 0; while (line != null) { String[] elements = line.split(at.tuwien.ifs.somtoolbox.util.StringUtils.REGEX_SPACE_OR_TAB); int x = index % xSize; int y = index / xSize; int z = 0; unitInfo[x][y][z] = new UnitInformation(dim); for (int i = 0; i < unitInfo[x][y][z].vector.length; i++) { unitInfo[x][y][z].vector[i] = Double.parseDouble(elements[i]); } index++; line = br.readLine(); } // if existing, read the bestmatch file to construct the unit information if (StringUtils.isNotBlank(bmFile)) { br = FileUtils.openFile("SOMPAK File", bmFile); line = FileUtils.consumeHeaderComments(br); // first line: map size line = line.trim().substring(1).trim(); int ySizeBM = Integer.parseInt(line.split(" ")[0]); // first rows int xSizeBM = Integer.parseInt(line.split(" ")[1]); // then columns // check for mismatch if (xSizeBM != xSize) { throw new SOMToolboxException("Header in weights (" + weightsFile + ") and bestmatches (" + bmFile + ") differ in xSize: " + xSize + " <-> " + xSizeBM); } if (ySizeBM != ySize) { throw new SOMToolboxException("Header in weights (" + weightsFile + ") and bestmatches (" + bmFile + ") differ in ySize: " + ySize + " <-> " + ySizeBM); } // second line: number of lines line = br.readLine(); // just consume it, we don't really need it (except if we add some sanity check) while ((line = br.readLine()) != null) { String[] lineElements = line.trim().split("\t"); String label = lineElements[0].trim(); int yPos = Integer.parseInt(lineElements[1].trim()); int xPos = Integer.parseInt(lineElements[2].trim()); ArrayUtils.add(unitInfo[xPos][yPos][0].mappedVecs, label); } } }
From source file:com.hihsoft.baseclass.web.controller.BaseController.java
/** * validator. Spring?validators,????validator. * /*from w ww. ja va 2 s . c om*/ * @param validator * the validator */ protected void addValidator(final Validator validator) { ArrayUtils.add(getValidators(), validator); }
From source file:info.magnolia.cms.filters.AbstractMgnlFilter.java
public void addBypass(Voter voter) { this.bypasses = (Voter[]) ArrayUtils.add(this.bypasses, voter); }
From source file:com.aionemu.gameserver.world.MapRegion.java
/** * Add neighbour region to this region neighbours list. * * @param neighbour */ void addNeighbourRegion(MapRegion neighbour) { neighbours = (MapRegion[]) ArrayUtils.add(neighbours, neighbour); }
From source file:net.navasoft.madcoin.backend.services.vo.request.SuccessRequestVOWrapper.java
private Method[] filterMethods() { Method[] filtered = new Method[] {}; for (Method all : this.helper.getMethods()) { if (all.getName().startsWith("get") && !all.getName().equals("getClass")) { filtered = (Method[]) ArrayUtils.add(filtered, all); }//from www . j av a 2 s . c o m } return filtered; }
From source file:gda.device.detector.countertimer.TfgScalerWithLogValues.java
protected double[] appendLogValues(double[] output) { Double[] logs = new Double[2]; // find which col is which I0, It and Iref Double[] values = getI0ItIRef(output); // NOTE Assumes that the order of the data (time, I0, It, Iref...) // for dark current does not change. logs[0] = Math.log(values[0] / values[1]); logs[1] = Math.log(values[1] / values[2]); // always return a numerical value if (logs[0].isInfinite() || logs[0].isNaN()) { logs[0] = 0.0;//from w w w . jav a 2s .co m } if (logs[1].isInfinite() || logs[1].isNaN()) { logs[1] = 0.0; } // append to output array output = correctCounts(output, values); output = ArrayUtils.add(output, logs[0]); output = ArrayUtils.add(output, logs[1]); return output; }
From source file:com.blockwithme.hacktors.BlockType.java
/** Finalizes the initialization of an block of this type. */ public Block postInit(final Block block) { Preconditions.checkNotNull(block);/* w w w . j av a 2 s .c o m*/ Preconditions.checkArgument(block.getType() == this); block.setLife((life == -1) ? -1 : life); if ((this == BlockType.ClosedChest) || (this == BlockType.OpenChest)) { final int count = Util.nextInt(2) + 1; Item[] content = block.getContent(); for (int i = 0; i < count; i++) { content = (Item[]) ArrayUtils.add(content, Item.create()); } block.setContent(content); } return block; }
From source file:com.aionemu.gameserver.controllers.ObserveController.java
/** * // w w w. ja va 2 s. c o m * @param observer */ public void addObserver(ActionObserver observer) { synchronized (observers) { observers = (ActionObserver[]) ArrayUtils.add(observers, observer); } }