Java Code Examples for com.google.common.base.Charsets#US_ASCII

The following examples show how to use com.google.common.base.Charsets#US_ASCII . 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: CodeGenerator.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
CodeGenerator(
    CodeConsumer consumer,
    CompilerOptions options) {
  cc = consumer;

  Charset outputCharset = options.getOutputCharset();
  if (outputCharset == null || outputCharset == Charsets.US_ASCII) {
    // If we want our default (pretending to be UTF-8, but escaping anything
    // outside of straight ASCII), then don't use the encoder, but
    // just special-case the code.  This keeps the normal path through
    // the code identical to how it's been for years.
    this.outputCharsetEncoder = null;
  } else {
    this.outputCharsetEncoder = outputCharset.newEncoder();
  }
  this.preferSingleQuotes = options.preferSingleQuotes;
  this.trustedStrings = options.trustedStrings;
}
 
Example 2
Source File: Closure_123_CodeGenerator_s.java    From coming with MIT License 6 votes vote down vote up
CodeGenerator(
    CodeConsumer consumer,
    CompilerOptions options) {
  cc = consumer;

  Charset outputCharset = options.getOutputCharset();
  if (outputCharset == null || outputCharset == Charsets.US_ASCII) {
    // If we want our default (pretending to be UTF-8, but escaping anything
    // outside of straight ASCII), then don't use the encoder, but
    // just special-case the code.  This keeps the normal path through
    // the code identical to how it's been for years.
    this.outputCharsetEncoder = null;
  } else {
    this.outputCharsetEncoder = outputCharset.newEncoder();
  }
  this.preferSingleQuotes = options.preferSingleQuotes;
  this.trustedStrings = options.trustedStrings;
  this.languageMode = options.getLanguageOut();
}
 
Example 3
Source File: Closure_128_CodeGenerator_t.java    From coming with MIT License 6 votes vote down vote up
CodeGenerator(
    CodeConsumer consumer,
    CompilerOptions options) {
  cc = consumer;

  Charset outputCharset = options.getOutputCharset();
  if (outputCharset == null || outputCharset == Charsets.US_ASCII) {
    // If we want our default (pretending to be UTF-8, but escaping anything
    // outside of straight ASCII), then don't use the encoder, but
    // just special-case the code.  This keeps the normal path through
    // the code identical to how it's been for years.
    this.outputCharsetEncoder = null;
  } else {
    this.outputCharsetEncoder = outputCharset.newEncoder();
  }
  this.preferSingleQuotes = options.preferSingleQuotes;
  this.trustedStrings = options.trustedStrings;
}
 
Example 4
Source File: RedisCommandInvoker.java    From hanboDB with Apache License 2.0 6 votes vote down vote up
public Reply handlerEvent(ChannelHandlerContext ctx, Command msg) throws RedisException {
    byte[] name = msg.getName();

    for (int i = 0; i < name.length; i++) {
        byte b = name[i];
        if (b >= 'A' && b <= 'Z') {
            name[i] = (byte) (b + LOWER_DIFF);
        }
    }
    Wrapper wrapper = methods.get(new BytesKey(name));
    Reply reply;
    if (wrapper == null) {
        reply = new ErrorReply("unknown command '" + new String(name, Charsets.US_ASCII) + "'");
        //if started tx,then invoker discard method and setErrorMsg
        if (rs.hasOpenTx()) {
            rs.discard();
            rs.setTXError();
        }
    } else {
        reply = wrapper.execute(msg, ctx);
    }
    return reply;
}
 
Example 5
Source File: Closure_52_CodeGenerator_t.java    From coming with MIT License 5 votes vote down vote up
CodeGenerator(
    CodeConsumer consumer, Charset outputCharset) {
  cc = consumer;
  if (outputCharset == null || outputCharset == Charsets.US_ASCII) {
    // If we want our default (pretending to be UTF-8, but escaping anything
    // outside of straight ASCII), then don't use the encoder, but
    // just special-case the code.  This keeps the normal path through
    // the code identical to how it's been for years.
    this.outputCharsetEncoder = null;
  } else {
    this.outputCharsetEncoder = outputCharset.newEncoder();
  }
}
 
Example 6
Source File: BuildCheckpoints.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
private static void writeTextualCheckpoints(TreeMap<Integer, StoredBlock> checkpoints, File file) throws IOException {
    PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), Charsets.US_ASCII));
    writer.println("TXT CHECKPOINTS 1");
    writer.println("0"); // Number of signatures to read. Do this later.
    writer.println(checkpoints.size());
    ByteBuffer buffer = ByteBuffer.allocate(StoredBlock.COMPACT_SERIALIZED_SIZE);
    for (StoredBlock block : checkpoints.values()) {
        block.serializeCompact(buffer);
        writer.println(CheckpointManager.BASE64.encode(buffer.array()));
        buffer.position(0);
    }
    writer.close();
    System.out.println("Checkpoints written to '" + file.getCanonicalPath() + "'.");
}
 
Example 7
Source File: Closure_73_CodeGenerator_t.java    From coming with MIT License 5 votes vote down vote up
CodeGenerator(
    CodeConsumer consumer, Charset outputCharset) {
  cc = consumer;
  if (outputCharset == null || outputCharset == Charsets.US_ASCII) {
    // If we want our default (pretending to be UTF-8, but escaping anything
    // outside of straight ASCII), then don't use the encoder, but
    // just special-case the code.  This keeps the normal path through
    // the code identical to how it's been for years.
    this.outputCharsetEncoder = null;
  } else {
    this.outputCharsetEncoder = outputCharset.newEncoder();
  }
}
 
Example 8
Source File: Closure_73_CodeGenerator_s.java    From coming with MIT License 5 votes vote down vote up
CodeGenerator(
    CodeConsumer consumer, Charset outputCharset) {
  cc = consumer;
  if (outputCharset == null || outputCharset == Charsets.US_ASCII) {
    // If we want our default (pretending to be UTF-8, but escaping anything
    // outside of straight ASCII), then don't use the encoder, but
    // just special-case the code.  This keeps the normal path through
    // the code identical to how it's been for years.
    this.outputCharsetEncoder = null;
  } else {
    this.outputCharsetEncoder = outputCharset.newEncoder();
  }
}
 
Example 9
Source File: Closure_34_CodeGenerator_t.java    From coming with MIT License 5 votes vote down vote up
CodeGenerator(
    CodeConsumer consumer, Charset outputCharset) {
  cc = consumer;
  if (outputCharset == null || outputCharset == Charsets.US_ASCII) {
    // If we want our default (pretending to be UTF-8, but escaping anything
    // outside of straight ASCII), then don't use the encoder, but
    // just special-case the code.  This keeps the normal path through
    // the code identical to how it's been for years.
    this.outputCharsetEncoder = null;
  } else {
    this.outputCharsetEncoder = outputCharset.newEncoder();
  }
}
 
Example 10
Source File: Closure_34_CodeGenerator_s.java    From coming with MIT License 5 votes vote down vote up
CodeGenerator(
    CodeConsumer consumer, Charset outputCharset) {
  cc = consumer;
  if (outputCharset == null || outputCharset == Charsets.US_ASCII) {
    // If we want our default (pretending to be UTF-8, but escaping anything
    // outside of straight ASCII), then don't use the encoder, but
    // just special-case the code.  This keeps the normal path through
    // the code identical to how it's been for years.
    this.outputCharsetEncoder = null;
  } else {
    this.outputCharsetEncoder = outputCharset.newEncoder();
  }
}
 
Example 11
Source File: MultipartHttpMessageConverter.java    From vertx-rest-client with Apache License 2.0 5 votes vote down vote up
/**
 * Generate a multipart boundary.
 * <p>The default implementation returns a random boundary.
 * Can be overridden in subclasses.
 */
private String generateMultipartBoundary() {
    byte[] boundary = new byte[this.random.nextInt(11) + 30];
    for (int i = 0; i < boundary.length; i++) {
        boundary[i] = BOUNDARY_CHARS[this.random.nextInt(BOUNDARY_CHARS.length)];
    }

    final String constructedBoundry = "----" + new String(boundary, Charsets.US_ASCII);
    return constructedBoundry.toLowerCase();
}
 
Example 12
Source File: BuildCheckpoints.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
private static void writeTextualCheckpoints(TreeMap<Integer, StoredBlock> checkpoints, File file) throws IOException {
    PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), Charsets.US_ASCII));
    writer.println("TXT CHECKPOINTS 1");
    writer.println("0"); // Number of signatures to read. Do this later.
    writer.println(checkpoints.size());
    ByteBuffer buffer = ByteBuffer.allocate(StoredBlock.COMPACT_SERIALIZED_SIZE);
    for (StoredBlock block : checkpoints.values()) {
        block.serializeCompact(buffer);
        writer.println(CheckpointManager.BASE64.encode(buffer.array()));
        buffer.position(0);
    }
    writer.close();
    System.out.println("Checkpoints written to '" + file.getCanonicalPath() + "'.");
}
 
Example 13
Source File: ResourceConfiguration.java    From android-arscblamer with Apache License 2.0 5 votes vote down vote up
private static String unpackLanguageOrRegion(byte[] value, int base) {
  Preconditions.checkState(value.length == 2, "Language or region value must be 2 bytes.");
  if (value[0] == 0 && value[1] == 0) {
    return "";
  }
  if ((UnsignedBytes.toInt(value[0]) & 0x80) != 0) {
    byte[] result = new byte[3];
    result[0] = (byte) (base + (value[1] & 0x1F));
    result[1] = (byte) (base + ((value[1] & 0xE0) >>> 5) + ((value[0] & 0x03) << 3));
    result[2] = (byte) (base + ((value[0] & 0x7C) >>> 2));
    return new String(result, Charsets.US_ASCII);
  }
  return new String(value, Charsets.US_ASCII);
}
 
Example 14
Source File: Closure_77_CodeGenerator_s.java    From coming with MIT License 5 votes vote down vote up
CodeGenerator(
    CodeConsumer consumer, Charset outputCharset) {
  cc = consumer;
  if (outputCharset == null || outputCharset == Charsets.US_ASCII) {
    // If we want our default (pretending to be UTF-8, but escaping anything
    // outside of straight ASCII), then don't use the encoder, but
    // just special-case the code.  This keeps the normal path through
    // the code identical to how it's been for years.
    this.outputCharsetEncoder = null;
  } else {
    this.outputCharsetEncoder = outputCharset.newEncoder();
  }
}
 
Example 15
Source File: Closure_77_CodeGenerator_t.java    From coming with MIT License 5 votes vote down vote up
CodeGenerator(
    CodeConsumer consumer, Charset outputCharset) {
  cc = consumer;
  if (outputCharset == null || outputCharset == Charsets.US_ASCII) {
    // If we want our default (pretending to be UTF-8, but escaping anything
    // outside of straight ASCII), then don't use the encoder, but
    // just special-case the code.  This keeps the normal path through
    // the code identical to how it's been for years.
    this.outputCharsetEncoder = null;
  } else {
    this.outputCharsetEncoder = outputCharset.newEncoder();
  }
}
 
Example 16
Source File: BuildRepetitionSet.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
public static void main(String[] arg) throws IOException {
	if (arg.length == 0) {
		System.err.println("Usage: " + BuildRepetitionSet.class.getSimpleName() + " REPETITIONSET");
		System.exit(1);
	}

	final FastBufferedReader fastBufferedReader = new FastBufferedReader(new InputStreamReader(System.in, Charsets.US_ASCII));
	final MutableString s = new MutableString();
	final LongOpenHashSet repeatedSet = new LongOpenHashSet();
	final String outputFilename = arg[0];
	final ProgressLogger pl = new ProgressLogger();

	MutableString lastUrl = new MutableString();
	pl.itemsName = "lines";
	pl.start("Reading... ");
	while(fastBufferedReader.readLine(s) != null) {
		final int firstTab = s.indexOf('\t');
		final int secondTab = s.indexOf('\t', firstTab + 1);
		MutableString url = s.substring(secondTab + 1);
		if (url.equals(lastUrl)) {
			final int storeIndex = Integer.parseInt(new String(s.array(), 0, firstTab));
			final long storePosition = Long.parseLong(new String(s.array(), firstTab + 1, secondTab - firstTab - 1));
			repeatedSet.add((long)storeIndex << 48 | storePosition);
			System.out.print(storeIndex);
			System.out.print('\t');
			System.out.print(storePosition);
			System.out.print('\t');
			System.out.println(url);
		}

		lastUrl = url;
		pl.lightUpdate();
	}

	pl.done();

	fastBufferedReader.close();
	BinIO.storeObject(repeatedSet, outputFilename);
}
 
Example 17
Source File: 1_CodeGenerator.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
CodeGenerator(
    CodeConsumer consumer, Charset outputCharset) {
  cc = consumer;
  if (outputCharset == null || outputCharset == Charsets.US_ASCII) {
    // If we want our default (pretending to be UTF-8, but escaping anything
    // outside of straight ASCII), then don't use the encoder, but
    // just special-case the code.  This keeps the normal path through
    // the code identical to how it's been for years.
    this.outputCharsetEncoder = null;
  } else {
    this.outputCharsetEncoder = outputCharset.newEncoder();
  }
}
 
Example 18
Source File: 1_CodeGenerator.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
CodeGenerator(
    CodeConsumer consumer, Charset outputCharset) {
  cc = consumer;
  if (outputCharset == null || outputCharset == Charsets.US_ASCII) {
    // If we want our default (pretending to be UTF-8, but escaping anything
    // outside of straight ASCII), then don't use the encoder, but
    // just special-case the code.  This keeps the normal path through
    // the code identical to how it's been for years.
    this.outputCharsetEncoder = null;
  } else {
    this.outputCharsetEncoder = outputCharset.newEncoder();
  }
}
 
Example 19
Source File: AsciiLongArrayView.java    From stratosphere with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
  return "[" + new String(buffer, offset, numBytes, Charsets.US_ASCII) + "] (buffer length: " + buffer.length +
      ", offset: " + offset + ", numBytes: " + numBytes + ")";
}
 
Example 20
Source File: RestTemplateBasicLiveTest.java    From tutorials with MIT License 4 votes vote down vote up
private String getBase64EncodedLogPass() {
    final String logPass = "user1:user1Pass";
    final byte[] authHeaderBytes = encodeBase64(logPass.getBytes(Charsets.US_ASCII));
    return new String(authHeaderBytes, Charsets.US_ASCII);
}