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

The following examples show how to use com.google.common.base.Charsets#ISO_8859_1 . 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: AvdManager.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Writes a .ini file from a set of properties, using UTF-8 encoding.
 * The keys are sorted.
 * The file should be read back later by {@link #parseIniFile(IAbstractFile, ILogger)}.
 *
 * @param iniFile The file to generate.
 * @param values The properties to place in the ini file.
 * @param addEncoding When true, add a property {@link #AVD_INI_ENCODING} indicating the
 *                    encoding used to write the file.
 * @throws IOException if {@link FileWriter} fails to open, write or close the file.
 */
private static void writeIniFile(File iniFile, Map<String, String> values, boolean addEncoding)
        throws IOException {

    Charset charset = Charsets.ISO_8859_1;
    OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(iniFile), charset);

    if (addEncoding) {
        // Write down the charset used in case we want to use it later.
        writer.write(String.format("%1$s=%2$s\n", AVD_INI_ENCODING, charset.name()));
    }

    ArrayList<String> keys = new ArrayList<String>(values.keySet());
    Collections.sort(keys);

    for (String key : keys) {
        String value = values.get(key);
        writer.write(String.format("%1$s=%2$s\n", key, value));
    }
    writer.close();
}
 
Example 2
Source File: InputRowParserSerdeTest.java    From druid-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testStringInputRowParserSerdeMultiCharset() throws Exception
{
  Charset[] testCharsets = {
      Charsets.US_ASCII, Charsets.ISO_8859_1, Charsets.UTF_8,
      Charsets.UTF_16BE, Charsets.UTF_16LE, Charsets.UTF_16
  };

  for (Charset testCharset : testCharsets) {
    InputRow parsed = testCharsetParseHelper(testCharset);
    Assert.assertEquals(ImmutableList.of("foo", "bar"), parsed.getDimensions());
    Assert.assertEquals(ImmutableList.of("x"), parsed.getDimension("foo"));
    Assert.assertEquals(ImmutableList.of("y"), parsed.getDimension("bar"));
    Assert.assertEquals(new DateTime("3000").getMillis(), parsed.getTimestampFromEpoch());
  }
}
 
Example 3
Source File: Servlets.java    From dubai with MIT License 6 votes vote down vote up
/**
 * 设置让浏览器弹出下载对话框的Header.
 * 
 * @param fileName 下载后的文件名.
 */
public static void setFileDownloadHeader(HttpServletRequest request, HttpServletResponse response, String fileName) {
	// 中文文件名支持
	String encodedfileName = null;
	// 替换空格,否则firefox下有空格文件名会被截断,其他浏览器会将空格替换成+号
	encodedfileName = fileName.trim().replaceAll(" ", "_");
	String agent = request.getHeader("User-Agent");
	boolean isMSIE = (agent != null && agent.toUpperCase().indexOf("MSIE") != -1);
	if (isMSIE) {
		encodedfileName = Encodes.urlEncode(fileName);
	} else {
		encodedfileName = new String(fileName.getBytes(), Charsets.ISO_8859_1);
	}

	response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedfileName + "\"");

}
 
Example 4
Source File: Servlets.java    From dpCms with Apache License 2.0 6 votes vote down vote up
/**
 * 设置让浏览器弹出下载对话框的Header.
 * 
 * @param fileName 下载后的文件名.
 */
public static void setFileDownloadHeader(HttpServletRequest request, HttpServletResponse response, String fileName) {
	// 中文文件名支持
	String encodedfileName = null;
	// 替换空格,否则firefox下有空格文件名会被截断,其他浏览器会将空格替换成+号
	encodedfileName = fileName.trim().replaceAll(" ", "_");
	String agent = request.getHeader("User-Agent");
	boolean isMSIE = (agent != null && agent.toUpperCase().indexOf("MSIE") != -1);
	if (isMSIE) {
		encodedfileName = Encodes.urlEncode(fileName);
	} else {
		encodedfileName = new String(fileName.getBytes(), Charsets.ISO_8859_1);
	}

	response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedfileName + "\"");

}
 
Example 5
Source File: Servlets.java    From spring-boot-quickstart with Apache License 2.0 6 votes vote down vote up
/**
 * 设置让浏览器弹出下载对话框的Header.
 * 
 * @param fileName 下载后的文件名.
 */
public static void setFileDownloadHeader(HttpServletRequest request, HttpServletResponse response, String fileName) {
	// 中文文件名支持
	String encodedfileName = null;
	// 替换空格,否则firefox下有空格文件名会被截断,其他浏览器会将空格替换成+号
	encodedfileName = fileName.trim().replaceAll(" ", "_");
	String agent = request.getHeader("User-Agent");
	boolean isMSIE = (agent != null && agent.toUpperCase().indexOf("MSIE") != -1);
	if (isMSIE) {
		encodedfileName = Encodes.urlEncode(fileName);
	} else {
		encodedfileName = new String(fileName.getBytes(), Charsets.ISO_8859_1);
	}

	response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedfileName + "\"");

}
 
Example 6
Source File: IpmiRAKPMessage1.java    From ipmi4j with Apache License 2.0 6 votes vote down vote up
@Override
protected void fromWireUnchecked(IpmiPacketContext context, ByteBuffer buffer) {
    messageTag = buffer.get();
    assertWireBytesZero(buffer, 3);
    systemSessionId = fromWireIntLE(buffer);
    consoleRandom = readBytes(buffer, 16);
    byte requestedMaximumPrivilegeLevelByte = buffer.get();
    requestedMaximumPrivilegeLevel = Code.fromByte(RequestedMaximumPrivilegeLevel.class, (byte) (requestedMaximumPrivilegeLevelByte & RequestedMaximumPrivilegeLevel.MASK));
    privilegeLookupMode = Code.fromByte(PrivilegeLookupMode.class, (byte) (requestedMaximumPrivilegeLevelByte & PrivilegeLookupMode.MASK));
    assertWireBytesZero(buffer, 2);
    int usernameLength = UnsignedBytes.toInt(buffer.get());
    if (usernameLength > 0) {
        byte[] usernameBytes = readBytes(buffer, usernameLength);
        username = new String(usernameBytes, Charsets.ISO_8859_1);
    } else {
        username = null;
    }
}
 
Example 7
Source File: RuntimeConfiguration.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
/** Adds a (or a set of) new IPv4 to the black list; the IPv4 can be specified directly or it can be a file (prefixed by
 *  <code>file:</code>).
 *
 * @param spec the specification (an IP address, or a file prefixed by <code>file</code>).
 * @throws ConfigurationException
 * @throws FileNotFoundException
 */
public void addBlackListedIPv4(final String spec) throws ConfigurationException, FileNotFoundException {
		if (spec.length() == 0) return; // Skip empty specs
		if (spec.startsWith("file:")) {
			final LineIterator lineIterator = new LineIterator(new FastBufferedReader(new InputStreamReader(new FileInputStream(spec.substring(5)), Charsets.ISO_8859_1)));
			while (lineIterator.hasNext()) {
				final MutableString line = lineIterator.next();
				if (line.length() > 0) blackListedIPv4Addresses.add(handleIPv4(line.toString()));
			}
		}
		else blackListedIPv4Addresses.add(handleIPv4(spec));
}
 
Example 8
Source File: DhcpMessageDecoder.java    From dhcp4j with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static String decodeString(@Nonnull ByteBuffer buffer, @Nonnegative int len)
        throws IOException {
    byte[] bytes = decodeBytes(buffer, len);
    // find zero-terminator
    int slen = Bytes.indexOf(bytes, (byte) 0);
    if (slen < 0)
        slen = bytes.length;
    return new String(bytes, 0, slen, Charsets.ISO_8859_1);
}
 
Example 9
Source File: ViewResource.java    From dropwizard-java8 with Apache License 2.0 5 votes vote down vote up
@GET
@Produces("text/html;charset=ISO-8859-1")
@Path("/iso88591.mustache")
public View mustacheISO88591() {
    return new View("/views/mustache/iso88591.mustache", Charsets.ISO_8859_1) {
    };
}
 
Example 10
Source File: ViewResource.java    From dropwizard-java8 with Apache License 2.0 5 votes vote down vote up
@GET
@Produces("text/html;charset=ISO-8859-1")
@Path("/iso88591.ftl")
public View freemarkerISO88591() {
    return new View("/views/ftl/iso88591.ftl", Charsets.ISO_8859_1) {
    };
}
 
Example 11
Source File: DhcpMessageDecoder.java    From dhcp4j with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static String decodeString(@Nonnull ByteBuffer buffer, @Nonnegative int len)
        throws IOException {
    byte[] bytes = decodeBytes(buffer, len);
    // find zero-terminator
    int slen = Bytes.indexOf(bytes, (byte) 0);
    if (slen < 0)
        slen = bytes.length;
    return new String(bytes, 0, slen, Charsets.ISO_8859_1);
}
 
Example 12
Source File: AntlrToolFacadeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testNewXtextOldAntlrDifferentEncoding() {
	setMode(Mode.OLD);
	Charset encoding = Charset.defaultCharset().equals(Charsets.ISO_8859_1) ? Charsets.UTF_8 : Charsets.ISO_8859_1; 
	TestableToolFacade facade = new TestableToolFacade();
	facade.runWithEncodingAndParams("", encoding.name());
}
 
Example 13
Source File: RuntimeConfiguration.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
/** Adds a (or a set of) new host to the black list; the host can be specified directly or it can be a file (prefixed by
 *  <code>file:</code>).
 *
 * @param spec the specification (a host, or a file prefixed by <code>file</code>).
 * @throws ConfigurationException
 * @throws FileNotFoundException
 */
public void addBlackListedHost(final String spec) throws ConfigurationException, FileNotFoundException 	{
	if (spec.length() == 0) return; // Skip empty specs
	if (spec.startsWith("file:")) {
		final LineIterator lineIterator = new LineIterator(new FastBufferedReader(new InputStreamReader(new FileInputStream(spec.substring(5)), Charsets.ISO_8859_1)));
		while (lineIterator.hasNext()) {
			final MutableString line = lineIterator.next();
			blackListedHostHashes.add(line.toString().trim().hashCode());
		}
	}
	else blackListedHostHashes.add(spec.trim().hashCode());
}
 
Example 14
Source File: StringOption.java    From dhcp4j with Apache License 2.0 4 votes vote down vote up
@Nonnull
public String getStringValue() {
    return new String(getStringData(), Charsets.ISO_8859_1);
}
 
Example 15
Source File: ObfuscateKey.java    From SkyTube with GNU General Public License v3.0 4 votes vote down vote up
public String decrypt(String input) {
    byte[] raw = encrypt(parseHexBinary(input));
    return new String(raw, Charsets.ISO_8859_1);
}
 
Example 16
Source File: BURLTest.java    From BUbiNG with Apache License 2.0 4 votes vote down vote up
public static String hostWithStartEnd(byte[] url) {
	final int startOfHost = BURL.startOfHost(url);
	final int lengthOfHost = BURL.lengthOfHost(url, startOfHost);
	return new String(url, startOfHost, lengthOfHost, Charsets.ISO_8859_1);
}
 
Example 17
Source File: StringOption.java    From dhcp4j with Apache License 2.0 4 votes vote down vote up
@Nonnull
public String getStringValue() {
    return new String(getStringData(), Charsets.ISO_8859_1);
}
 
Example 18
Source File: BubingJob.java    From BUbiNG with Apache License 2.0 2 votes vote down vote up
/**
  * A string representation of this job
  *
  * @return the URI of this job in string format
  */
 @Override
public String toString() {
	 return "[" + new String(url.elements(), 0, url.size(), Charsets.ISO_8859_1) + "]";
 }