public static String[] split(String splittee,String splitChar) { return split(splittee,splitChar,true); }
public byte[] decode(byte[] buf) { return JOrphanUtils.baToHexString(buf).getBytes(); } }
/** * @param value String value to test * @return true if value is null or empty trimmed */ protected static boolean isNullOrEmptyTrimmed(String value) { return JOrphanUtils.isBlank(value); } }
/** * {@inheritDoc} */ @Override public String read(InputStream is, SampleResult sampleResult) throws ReadException{ byte[] msg = new byte[0]; int msgLen = 0; byte[] lengthBuffer = new byte[lengthPrefixLen]; try { if (is.read(lengthBuffer, 0, lengthPrefixLen) == lengthPrefixLen) { sampleResult.latencyEnd(); msgLen = byteArrayToInt(lengthBuffer); msg = new byte[msgLen]; int bytes = JOrphanUtils.read(is, msg, 0, msgLen); if (bytes < msgLen) { log.warn("Incomplete message read, expected: {} got: {}", msgLen, bytes); } } String buffer = JOrphanUtils.baToHexString(msg); if(log.isDebugEnabled()) { log.debug("Read: " + msgLen + "\n" + buffer); } return buffer; } catch(IOException e) { throw new ReadException("", e, JOrphanUtils.baToHexString(msg)); } }
@Override public void close() { JOrphanUtils.closeQuietly(isr); JOrphanUtils.closeQuietly(fis); JOrphanUtils.closeQuietly(reader); } }
@Override public ByteBuffer encode(String data) { if (os == null) { try { os = new FileOutputStream(new File("DNSJavaDecoderToRawData.out")); } catch (FileNotFoundException ex) { throw new RuntimeException(ex); } } Message msg = new Message(); String recs[] = data.split(NL); for (String rec : recs) { msg.addRecord(getRecord(rec), Section.QUESTION); } try { final byte[] ba1 = msg.toWire(); os.write(Integer.toString(ba1.length * 2).getBytes("cp866")); os.write('\n'); os.write(JOrphanUtils.baToHexBytes(ba1)); os.write('\n'); } catch (IOException ex) { throw new RuntimeException(ex); } return ByteBuffer.wrap(msg.toWire()); } }
/** * Throw {@link IllegalArgumentException} if folder cannot be written to either: * <ul> * <li>Because it exists but is not a folder</li> * <li>Because it exists but is not empty</li> * <li>Because it does not exist but cannot be created</li> * </ul> * @param folder {@link File} * * @throws IllegalArgumentException when folder can't be written to */ public static void canSafelyWriteToFolder(File folder) { canSafelyWriteToFolder(folder, false); } /**
/** * This method is guaranteed to not throw any exception. If writer is already * closed then does nothing.<br> * Any buffered data is flushed by this method. */ @Override public void close() { JOrphanUtils.closeQuietly(writer); this.writer = null; }
@Override public ByteBuffer encode(String data) { if (os == null) { try { os = new FileOutputStream(new File("DNSJavaDecoderToRawData.out")); } catch (FileNotFoundException ex) { throw new RuntimeException(ex); } } Message msg = new Message(); String recs[] = data.split(NL); for (String rec : recs) { msg.addRecord(getRecord(rec), Section.QUESTION); } try { final byte[] ba1 = msg.toWire(); os.write(Integer.toString(ba1.length * 2).getBytes("cp866")); os.write('\n'); os.write(JOrphanUtils.baToHexBytes(ba1)); os.write('\n'); } catch (IOException ex) { throw new RuntimeException(ex); } return ByteBuffer.wrap(msg.toWire()); } }
/** * Extract option JMeter#REPORT_OUTPUT_FOLDER_OPT and if defined sets property * {@link JMeter#JMETER_REPORT_OUTPUT_DIR_PROPERTY} after checking folder can * be safely written to * @param parser {@link CLArgsParser} * @throws IllegalArgumentException */ private void extractAndSetReportOutputFolder(CLArgsParser parser, boolean deleteResultFile) { CLOption reportOutputFolderOpt = parser .getArgumentById(REPORT_OUTPUT_FOLDER_OPT); if(reportOutputFolderOpt != null) { String reportOutputFolder = parser.getArgumentById(REPORT_OUTPUT_FOLDER_OPT).getArgument(); File reportOutputFolderAsFile = new File(reportOutputFolder); JOrphanUtils.canSafelyWriteToFolder(reportOutputFolderAsFile, deleteResultFile); final String reportOutputFolderAbsPath = reportOutputFolderAsFile.getAbsolutePath(); log.info("Setting property '{}' to:'{}'", JMETER_REPORT_OUTPUT_DIR_PROPERTY, reportOutputFolderAbsPath); JMeterUtils.setProperty(JMETER_REPORT_OUTPUT_DIR_PROPERTY, reportOutputFolderAbsPath); } }
/** * Get the list of JDBC driver classname for the main databases * @return a String[] with the list of JDBC driver classname */ private String[] getListJDBCDriverClass() { return JOrphanUtils.split(JMeterUtils.getPropDefault("jdbc.config.jdbc.driver.class", ""), "|"); //$NON-NLS-1$ }
/** * Is a dynamic proxy defined? * * @param proxyHost the host to check * @param proxyPort the port to check * @return {@code true} iff both ProxyPort and ProxyHost are defined. */ protected boolean isDynamicProxy(String proxyHost, int proxyPort){ return !JOrphanUtils.isBlank(proxyHost) && proxyPort > 0; }
public byte[] decode(byte[] buf) { return JOrphanUtils.baToHexString(buf).getBytes(); } }
/** * {@inheritDoc} */ @Override public void close() { JOrphanUtils.closeQuietly(OUTPUT); }
byte[] md5Result = md.digest(); sampleResult.setBytes(totalBytes); return JOrphanUtils.baToHexBytes(md5Result);
JOrphanUtils.canSafelyWriteToFolder(outputDir);
/** * Get the check queries for the main databases * Based in https://stackoverflow.com/questions/10684244/dbcp-validationquery-for-different-databases * @return a String[] with the list of check queries */ private String[] getListCheckQuery() { return JOrphanUtils.split(JMeterUtils.getPropDefault("jdbc.config.check.query", ""), "|"); //$NON-NLS-1$ }
private BufferedWriter createBufferedWriter(FileEntry fileEntry) throws IOException { FileOutputStream fos = new FileOutputStream(fileEntry.file); OutputStreamWriter osw; // If file encoding is specified, write using that encoding, otherwise use default platform encoding String charsetName = fileEntry.charSetEncoding; if(!JOrphanUtils.isBlank(charsetName)) { osw = new OutputStreamWriter(fos, charsetName); } else { osw = new OutputStreamWriter(fos); } return new BufferedWriter(osw); }