Java Code Examples for org.apache.commons.lang3.StringUtils#isAsciiPrintable()
The following examples show how to use
org.apache.commons.lang3.StringUtils#isAsciiPrintable() .
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: ConsumeMQTT.java From localization_nifi with Apache License 2.0 | 6 votes |
@Override public void messageArrived(String topic, MqttMessage message) throws Exception { if (logger.isDebugEnabled()) { byte[] payload = message.getPayload(); String text = new String(payload, "UTF-8"); if (StringUtils.isAsciiPrintable(text)) { logger.debug("Message arrived from topic {}. Payload: {}", new Object[] {topic, text}); } else { logger.debug("Message arrived from topic {}. Binary value of size {}", new Object[] {topic, payload.length}); } } if (mqttQueue.size() >= maxQueueSize){ throw new IllegalStateException("The subscriber queue is full, cannot receive another message until the processor is scheduled to run."); } else { mqttQueue.add(new MQTTQueueMessage(topic, message)); } }
Example 2
Source File: ConsumeMQTT.java From nifi with Apache License 2.0 | 6 votes |
@Override public void messageArrived(String topic, MqttMessage message) throws Exception { if (logger.isDebugEnabled()) { byte[] payload = message.getPayload(); String text = new String(payload, "UTF-8"); if (StringUtils.isAsciiPrintable(text)) { logger.debug("Message arrived from topic {}. Payload: {}", new Object[] {topic, text}); } else { logger.debug("Message arrived from topic {}. Binary value of size {}", new Object[] {topic, payload.length}); } } if (mqttQueue.size() >= maxQueueSize){ throw new IllegalStateException("The subscriber queue is full, cannot receive another message until the processor is scheduled to run."); } else { mqttQueue.add(new MQTTQueueMessage(topic, message)); } }
Example 3
Source File: CommonLoadUploadFileAction.java From bamboobsc with Apache License 2.0 | 5 votes |
private void loadData(File file) throws ServiceException, Exception { if (StringUtils.isBlank(this.oid)) { return; } DefaultResult<SysUploadVO> result = this.sysUploadService.findForNoByteContent(this.oid); if (result.getValue()==null) { throw new ControllerException(result.getSystemMessage().getValue()); } SysUploadVO uploadData = result.getValue(); if (YesNo.YES.equals(uploadData.getIsFile())) { file = UploadSupportUtils.getRealFile(this.oid); if (!file.exists()) { return; } this.inputStream = new ByteArrayInputStream( FileUtils.readFileToByteArray(file) ); this.filename = file.getName(); } else { this.inputStream = new ByteArrayInputStream( UploadSupportUtils.getDataBytes(this.oid) ); this.filename = UploadSupportUtils.generateRealFileName(uploadData.getShowName()); } if ("view".equals(this.type)) { if (file!=null) { try { this.contentType = FSUtils.getMimeType(file); } catch (Exception e) { logger.warn( e.getMessage().toString() ); } } else { this.contentType = FSUtils.getMimeType(uploadData.getShowName()); } } if (!StringUtils.isAsciiPrintable(result.getValue().getShowName())) { String userAgent = super.defaultString(super.getHttpServletRequest().getHeader("User-Agent")).toLowerCase(); if (userAgent.indexOf("firefox")==-1) { // for chrome or other browser. this.filename = URLEncoder.encode(result.getValue().getShowName(), Constants.BASE_ENCODING); } return; } this.filename = result.getValue().getShowName(); }
Example 4
Source File: ScanForUnusedIl8nKeys.java From pcgen with GNU Lesser General Public License v2.1 | 5 votes |
/** * @param inputPropsFile * @param cleanPropsFile * @param unusedKeys * @throws IOException */ private static void outputCleanedProperties(File inputPropsFile, File cleanPropsFile, Collection<String> unusedKeys) throws IOException { List<String> lines; try (BufferedReader reader = new BufferedReader(new FileReader(inputPropsFile, StandardCharsets.UTF_8))) { lines = reader.lines().collect(Collectors.toList()); } Writer writer = new BufferedWriter(new PrintWriter(cleanPropsFile, StandardCharsets.UTF_8)); writer.write("# " + PROPERTIES_FILE + " with all unused keys removed as at " + LocalDateTime.now(Clock.systemUTC()) + "\n"); boolean lastLineBlank = false; for (String line : lines) { boolean found; if (lastLineBlank && line.trim().isEmpty()) { continue; } found = unusedKeys.stream().anyMatch(key -> line.startsWith(key + '=')); if (!found) { lastLineBlank = line.trim().isEmpty(); if (!StringUtils.isAsciiPrintable(line)) { System.out.println("Found a non adcii line " + line); } writer.write(line + "\n"); } } writer.close(); }
Example 5
Source File: ScanForUnusedIl8nKeys.java From pcgen with GNU Lesser General Public License v2.1 | 5 votes |
/** * @param inputPropsFile * @param cleanPropsFile * @param unusedKeys * @throws IOException */ private static void outputCleanedProperties(File inputPropsFile, File cleanPropsFile, Collection<String> unusedKeys) throws IOException { List<String> lines; try (BufferedReader reader = new BufferedReader(new FileReader(inputPropsFile, StandardCharsets.UTF_8))) { lines = reader.lines().collect(Collectors.toList()); } Writer writer = new BufferedWriter(new PrintWriter(cleanPropsFile, StandardCharsets.UTF_8)); writer.write("# " + PROPERTIES_FILE + " with all unused keys removed as at " + LocalDateTime.now(Clock.systemUTC()) + "\n"); boolean lastLineBlank = false; for (String line : lines) { boolean found; if (lastLineBlank && line.trim().isEmpty()) { continue; } found = unusedKeys.stream().anyMatch(key -> line.startsWith(key + '=')); if (!found) { lastLineBlank = line.trim().isEmpty(); if (!StringUtils.isAsciiPrintable(line)) { System.out.println("Found a non adcii line " + line); } writer.write(line + "\n"); } } writer.close(); }
Example 6
Source File: Utils.java From para with Apache License 2.0 | 5 votes |
/** * Quick and dirty singular to plural conversion. * @param singul a word * @return a guess of its plural form */ public static String singularToPlural(String singul) { if (!StringUtils.isAsciiPrintable(singul)) { return singul; } return (StringUtils.isBlank(singul) || singul.endsWith("es") || singul.endsWith("ies")) ? singul : (singul.endsWith("s") ? singul + "es" : (singul.endsWith("y") ? StringUtils.removeEndIgnoreCase(singul, "y") + "ies" : singul + "s")); }
Example 7
Source File: TranscodingService.java From airsonic-advanced with GNU General Public License v3.0 | 4 votes |
/** * Creates a transcoded input stream by interpreting the given command line string. * This includes the following: * <ul> * <li>Splitting the command line string to an array.</li> * <li>Replacing occurrences of "%s" with the path of the given music file.</li> * <li>Replacing occurrences of "%t" with the title of the given music file.</li> * <li>Replacing occurrences of "%l" with the album name of the given music file.</li> * <li>Replacing occurrences of "%a" with the artist name of the given music file.</li> * <li>Replacing occurrcences of "%b" with the max bitrate.</li> * <li>Replacing occurrcences of "%o" with the video time offset (used for scrubbing).</li> * <li>Replacing occurrcences of "%d" with the video duration (used for HLS).</li> * <li>Replacing occurrcences of "%w" with the video image width.</li> * <li>Replacing occurrcences of "%h" with the video image height.</li> * <li>Prepending the path of the transcoder directory if the transcoder is found there.</li> * </ul> * * @param command The command line string. * @param maxBitRate The maximum bitrate to use. May not be {@code null}. * @param videoTranscodingSettings Parameters used when transcoding video. May be {@code null}. * @param mediaFile The media file. * @param in Data to feed to the process. May be {@code null}. @return The newly created input stream. */ private TranscodeInputStream createTranscodeInputStream(String command, Integer maxBitRate, VideoTranscodingSettings videoTranscodingSettings, MediaFile mediaFile, InputStream in) throws IOException { String title = mediaFile.getTitle(); String album = mediaFile.getAlbumName(); String artist = mediaFile.getArtist(); if (title == null) { title = "Unknown Song"; } if (album == null) { album = "Unknown Album"; } if (artist == null) { artist = "Unknown Artist"; } List<String> result = new LinkedList<String>(Arrays.asList(StringUtil.split(command))); result.set(0, getTranscodeDirectory().resolve(result.get(0)).toString()); Path tmpFile = null; for (int i = 1; i < result.size(); i++) { String cmd = result.get(i); if (cmd.contains("%b")) { cmd = cmd.replace("%b", String.valueOf(maxBitRate)); } if (cmd.contains("%t")) { cmd = cmd.replace("%t", title); } if (cmd.contains("%l")) { cmd = cmd.replace("%l", album); } if (cmd.contains("%a")) { cmd = cmd.replace("%a", artist); } if (cmd.contains("%o") && videoTranscodingSettings != null) { cmd = cmd.replace("%o", String.valueOf(videoTranscodingSettings.getTimeOffset())); } if (cmd.contains("%d") && videoTranscodingSettings != null) { cmd = cmd.replace("%d", String.valueOf(videoTranscodingSettings.getDuration())); } if (cmd.contains("%w") && videoTranscodingSettings != null) { cmd = cmd.replace("%w", String.valueOf(videoTranscodingSettings.getWidth())); } if (cmd.contains("%h") && videoTranscodingSettings != null) { cmd = cmd.replace("%h", String.valueOf(videoTranscodingSettings.getHeight())); } if (cmd.contains("%s")) { // Work-around for filename character encoding problem on Windows. // Create temporary file, and feed this to the transcoder. Path path = mediaFile.getFile().toAbsolutePath(); if (Util.isWindows() && !mediaFile.isVideo() && !StringUtils.isAsciiPrintable(path.toString())) { tmpFile = Files.createTempFile("airsonic", "." + MoreFiles.getFileExtension(path)); tmpFile.toFile().deleteOnExit(); Files.copy(path, tmpFile, StandardCopyOption.REPLACE_EXISTING); LOG.debug("Created tmp file: " + tmpFile); cmd = cmd.replace("%s", tmpFile.toString()); } else { cmd = cmd.replace("%s", path.toString()); } } result.set(i, cmd); } return new TranscodeInputStream(new ProcessBuilder(result), in, tmpFile); }
Example 8
Source File: TranscodingService.java From airsonic with GNU General Public License v3.0 | 4 votes |
/** * Creates a transcoded input stream by interpreting the given command line string. * This includes the following: * <ul> * <li>Splitting the command line string to an array.</li> * <li>Replacing occurrences of "%s" with the path of the given music file.</li> * <li>Replacing occurrences of "%t" with the title of the given music file.</li> * <li>Replacing occurrences of "%l" with the album name of the given music file.</li> * <li>Replacing occurrences of "%a" with the artist name of the given music file.</li> * <li>Replacing occurrcences of "%b" with the max bitrate.</li> * <li>Replacing occurrcences of "%o" with the video time offset (used for scrubbing).</li> * <li>Replacing occurrcences of "%d" with the video duration (used for HLS).</li> * <li>Replacing occurrcences of "%w" with the video image width.</li> * <li>Replacing occurrcences of "%h" with the video image height.</li> * <li>Prepending the path of the transcoder directory if the transcoder is found there.</li> * </ul> * * @param command The command line string. * @param maxBitRate The maximum bitrate to use. May not be {@code null}. * @param videoTranscodingSettings Parameters used when transcoding video. May be {@code null}. * @param mediaFile The media file. * @param in Data to feed to the process. May be {@code null}. @return The newly created input stream. */ private TranscodeInputStream createTranscodeInputStream(String command, Integer maxBitRate, VideoTranscodingSettings videoTranscodingSettings, MediaFile mediaFile, InputStream in) throws IOException { String title = mediaFile.getTitle(); String album = mediaFile.getAlbumName(); String artist = mediaFile.getArtist(); if (title == null) { title = "Unknown Song"; } if (album == null) { album = "Unknown Album"; } if (artist == null) { artist = "Unknown Artist"; } List<String> result = new LinkedList<String>(Arrays.asList(StringUtil.split(command))); result.set(0, getTranscodeDirectory().getPath() + File.separatorChar + result.get(0)); File tmpFile = null; for (int i = 1; i < result.size(); i++) { String cmd = result.get(i); if (cmd.contains("%b")) { cmd = cmd.replace("%b", String.valueOf(maxBitRate)); } if (cmd.contains("%t")) { cmd = cmd.replace("%t", title); } if (cmd.contains("%l")) { cmd = cmd.replace("%l", album); } if (cmd.contains("%a")) { cmd = cmd.replace("%a", artist); } if (cmd.contains("%o") && videoTranscodingSettings != null) { cmd = cmd.replace("%o", String.valueOf(videoTranscodingSettings.getTimeOffset())); } if (cmd.contains("%d") && videoTranscodingSettings != null) { cmd = cmd.replace("%d", String.valueOf(videoTranscodingSettings.getDuration())); } if (cmd.contains("%w") && videoTranscodingSettings != null) { cmd = cmd.replace("%w", String.valueOf(videoTranscodingSettings.getWidth())); } if (cmd.contains("%h") && videoTranscodingSettings != null) { cmd = cmd.replace("%h", String.valueOf(videoTranscodingSettings.getHeight())); } if (cmd.contains("%s")) { // Work-around for filename character encoding problem on Windows. // Create temporary file, and feed this to the transcoder. String path = mediaFile.getFile().getAbsolutePath(); if (Util.isWindows() && !mediaFile.isVideo() && !StringUtils.isAsciiPrintable(path)) { tmpFile = File.createTempFile("airsonic", "." + FilenameUtils.getExtension(path)); tmpFile.deleteOnExit(); FileUtils.copyFile(new File(path), tmpFile); LOG.debug("Created tmp file: " + tmpFile); cmd = cmd.replace("%s", tmpFile.getPath()); } else { cmd = cmd.replace("%s", path); } } result.set(i, cmd); } return new TranscodeInputStream(new ProcessBuilder(result), in, tmpFile); }
Example 9
Source File: IsAsciiPrintable.java From vscrawler with Apache License 2.0 | 4 votes |
@Override protected boolean handle(CharSequence str) { return StringUtils.isAsciiPrintable(str); }
Example 10
Source File: AccountAttributeValidator.java From crushpaper with GNU Affero General Public License v3.0 | 4 votes |
/** Returns true if the password is valid. */ public static boolean isPasswordValid(String value) { return value != null && value.length() >= 8 && value.length() <= 20 && StringUtils.isAsciiPrintable(value); }
Example 11
Source File: ValidateUtils.java From spring-boot-doma2-sample with Apache License 2.0 | 2 votes |
/** * 値がASCII文字のみかチェックします。 * * @param value * @return */ public static boolean isAscii(String value) { return StringUtils.isAsciiPrintable(value); }