List of usage examples for java.nio.charset StandardCharsets US_ASCII
Charset US_ASCII
To view the source code for java.nio.charset StandardCharsets US_ASCII.
Click Source Link
From source file:Dengue.CDengueManager.java
private static void sendInfoToCPU(String pStrJSON, int pIntPort) { new Thread(() -> { try (Socket client = new Socket(InetAddress.getLocalHost(), pIntPort)) { Writer objWriter = Channels.newWriter(Channels.newChannel(client.getOutputStream()), StandardCharsets.US_ASCII.name()); objWriter.write(pStrJSON);/*from w w w . j ava 2s . co m*/ objWriter.flush(); client.shutdownOutput(); try (Reader objReader = Channels.newReader(Channels.newChannel(client.getInputStream()), StandardCharsets.US_ASCII.name()); BufferedReader objOutReader = new BufferedReader(objReader)) { System.out.println((char) objOutReader.read()); } } catch (IOException e) { System.out.println(e); } }).start(); }
From source file:Network.Dengue.CDengueHandler.java
@Override public void update(Observable o, Object arg) { int intReturn = 1; Socket objSocket = (Socket) arg; StringBuilder objSB = new StringBuilder(); try {//from w ww . j a v a 2 s . c o m BufferedReader objReader = new BufferedReader(new InputStreamReader(objSocket.getInputStream())); objSB.append(objReader.readLine()); new MDengue().addCluster(objSB.toString()); CNotificationManager.notifiyDengue(); CPublisherManager.publishDengue(); } catch (IOException | ParseException ex) { System.out.println(ex); intReturn = -1; } finally { try (Writer objWriter = Channels.newWriter(Channels.newChannel(objSocket.getOutputStream()), StandardCharsets.US_ASCII.name())) { objWriter.append(intReturn + ""); } catch (Exception ex) { System.out.println(ex); } } }
From source file:com.joyent.manta.client.crypto.EncryptedMetadataUtils.java
/** * Parses a plaintext metadata string and converts it into a {@link Map} of * keys and values.//from w ww . j a va 2 s .c o m * * @param plaintext Plaintext string in US-ASCII encoding * @return headers as map */ public static Map<String, String> plaintextMetadataAsMap(final String plaintext) { return plaintextMetadataAsMap(plaintext.getBytes(StandardCharsets.US_ASCII)); }
From source file:Network.Haze.CHazeHandler.java
@Override public void update(Observable o, Object arg) { int intReturn = 1; Socket objSocket = (Socket) arg; StringBuilder objSB = new StringBuilder(); try {/*from ww w. j a v a2 s .c o m*/ BufferedReader objReader = new BufferedReader(new InputStreamReader(objSocket.getInputStream())); objSB.append(objReader.readLine()); new MHaze().addHazeInfo(objSB.toString()); CNotificationManager.notifiyHaze(); CPublisherManager.publishHaze(); } catch (IOException | ParseException ex) { System.out.println(ex); intReturn = -1; } finally { try (Writer objWriter = Channels.newWriter(Channels.newChannel(objSocket.getOutputStream()), StandardCharsets.US_ASCII.name())) { objWriter.append(intReturn + ""); } catch (Exception ex) { System.out.println(ex); } } }
From source file:Network.CSMSHandler.java
@Override public void update(Observable o, Object arg) { Socket objSocket = (Socket) arg; int intSeq = -1; try {/*from w ww .jav a 2 s .c o m*/ JSONParser jsonParser = new JSONParser(); JSONObject objJSON = (JSONObject) jsonParser.parse(new InputStreamReader(objSocket.getInputStream())); int intTempSeq = Integer.parseInt(objJSON.get("id").toString()); for (CSMS objSMS : CSMSManager.loadFromJson((JSONArray) objJSON.get("sms"))) { CSMSFactory.getSMSSender().sendSMS(objSMS); } intSeq = intTempSeq; } catch (Exception ex) { System.out.println(ex); } finally { try (Writer objWriter = Channels.newWriter(Channels.newChannel(objSocket.getOutputStream()), StandardCharsets.US_ASCII.name())) { objWriter.write(intSeq + ""); objWriter.flush(); } catch (IOException ex) { System.out.println(ex); } } }
From source file:Network.CEmailHandler.java
@Override public void update(Observable o, Object arg) { Socket objSocket = (Socket) arg; int intSeq = -1; try {//from ww w . ja v a 2 s . com JSONParser jsonParser = new JSONParser(); JSONObject objJSON = (JSONObject) jsonParser.parse(new InputStreamReader(objSocket.getInputStream())); int intTempSeq = Integer.parseInt(objJSON.get("id").toString()); emailSender.getEmailsToBeSent((JSONArray) objJSON.get("messagesToBeSent")); emailSender.dispatchEmail(); intSeq = intTempSeq; } catch (IOException | ParseException | NumberFormatException ex) { System.out.println(ex); } finally { try (Writer objWriter = Channels.newWriter(Channels.newChannel(objSocket.getOutputStream()), StandardCharsets.US_ASCII.name())) { objWriter.write(intSeq + ""); objWriter.flush(); } catch (IOException ex) { System.out.println(ex); } } }
From source file:nl.salp.warcraft4j.dev.casc.model.ListCascFile.java
public ListCascFile(String filename) throws IllegalArgumentException { this(Optional.ofNullable(filename).filter(StringUtils::isNotEmpty).map(f -> f.replace('/', '\\')) .map(String::toUpperCase).map(f -> f.getBytes(StandardCharsets.US_ASCII)) .map(d -> JenkinsHash.hashLittle2(d, d.length)).orElseThrow( () -> new IllegalArgumentException("Unable to calculate a hash for an empty filename.")), filename, null, true);//from w w w.j a v a 2 s . c o m }
From source file:Network.CReportHandler.java
@Override public void update(Observable o, Object arg) { Socket objSocket = (Socket) arg; int intSeq = -1; try {// w w w. j av a2s .co m System.out.println("dasdasdasdsa"); /* JSONParser jsonParser = new JSONParser(); JSONObject objJSON = (JSONObject) jsonParser.parse(new InputStreamReader(objSocket.getInputStream())); System.out.println(objJSON.toJSONString()); int intTempSeq = Integer.parseInt(objJSON.get("id").toString()); CReport.genReport((JSONArray) objJSON.get("stats")); intSeq = intTempSeq;*/ // } catch (IOException | ParseException | NumberFormatException | COSVisitorException ex) { // System.out.println(ex); } finally { try (Writer objWriter = Channels.newWriter(Channels.newChannel(objSocket.getOutputStream()), StandardCharsets.US_ASCII.name())) { objWriter.write(intSeq + ""); objWriter.flush(); } catch (IOException ex) { System.out.println(ex); } } }
From source file:org.apache.tika.parser.dbf.DBFCell.java
String getString(Charset charset) { switch (colType) { case C://from w w w . ja v a 2 s.c o m return new String(getBytes(), charset).trim(); case D: return getFormattedDate(); case N: return new String(getBytes(), StandardCharsets.US_ASCII).trim(); case L: return new String(getBytes(), StandardCharsets.US_ASCII).trim(); case T: return getFormattedDateTime(); default: //TODO: find examples of other cell types for testing return new String(getBytes(), StandardCharsets.US_ASCII).trim(); } }
From source file:org.apache.hc.client5.testing.auth.BasicAuthTokenExtractor.java
public String extract(final String challengeResponse) throws HttpException { if (challengeResponse != null) { final int i = challengeResponse.indexOf(' '); if (i == -1) { throw new ProtocolException("Invalid challenge response: " + challengeResponse); }//from w ww.j av a2 s . co m final String authscheme = challengeResponse.substring(0, i); if (authscheme.equalsIgnoreCase("basic")) { final String s = challengeResponse.substring(i + 1).trim(); try { final byte[] credsRaw = s.getBytes(StandardCharsets.US_ASCII); final BinaryDecoder codec = new Base64(); return new String(codec.decode(credsRaw), StandardCharsets.US_ASCII); } catch (final DecoderException ex) { throw new ProtocolException("Malformed BASIC credentials"); } } } return null; }