Java Code Examples for java.nio.charset.StandardCharsets.ISO_8859_1

The following are Jave code examples for showing how to use ISO_8859_1 of the java.nio.charset.StandardCharsets class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: openjdk-jdk10   File: HeaderTableTest.java   Source Code and License Vote up 6 votes
@Test
public void entryPutAfterStaticArea() {
    HeaderTable table = new HeaderTable(256);
    int idx = table.length() + 1;
    assertThrows(IllegalArgumentException.class, () -> table.get(idx));

    byte[] bytes = new byte[32];
    rnd.nextBytes(bytes);
    String name = new String(bytes, StandardCharsets.ISO_8859_1);
    String value = "custom-value";

    table.put(name, value);
    HeaderField f = table.get(idx);
    assertEquals(name, f.name);
    assertEquals(value, f.value);
}
 
Example 2
Project: MetadataEditor   File: ID3v2LyricLine.java   Source Code and License Vote up 6 votes
/**
 * @param arr
 * @param offset
 * @throws NullPointerException
 * @throws IndexOutOfBoundsException
 */
public void readByteArray(byte[] arr, int offset) throws InvalidDataTypeException
{
    if (arr == null)
    {
        throw new NullPointerException("Byte array is null");
    }

    if ((offset < 0) || (offset >= arr.length))
    {
        throw new IndexOutOfBoundsException("Offset to byte array is out of bounds: offset = " + offset + ", array.length = " + arr.length);
    }

    //offset += ();
    text = new String(arr, offset, arr.length - offset - 4, StandardCharsets.ISO_8859_1);

    //text = text.substring(0, text.length() - 5);
    timeStamp = 0;

    for (int i = arr.length - 4; i < arr.length; i++)
    {
        timeStamp <<= 8;
        timeStamp += arr[i];
    }
}
 
Example 3
Project: MetadataEditor   File: VorbisSetupHeader.java   Source Code and License Vote up 5 votes
public void decodeHeader(byte[] b)
{
    int packetType = b[FIELD_PACKET_TYPE_POS];
    logger.fine("packetType" + packetType);
    String vorbis = new String(b, FIELD_CAPTURE_PATTERN_POS, FIELD_CAPTURE_PATTERN_LENGTH, StandardCharsets.ISO_8859_1);
    if (packetType == VorbisPacketType.SETUP_HEADER.getType() && vorbis.equals(CAPTURE_PATTERN))
    {
        isValid = true;
    }
}
 
Example 4
Project: openjdk-jdk10   File: BinaryPrimitivesTest.java   Source Code and License Vote up 5 votes
@Test
public void stringWriteChunked() {
    final int MAX_STRING_LENGTH = 8;
    final ByteBuffer bytes = ByteBuffer.allocate(MAX_STRING_LENGTH + 6);
    final CharBuffer chars = CharBuffer.allocate(MAX_STRING_LENGTH);
    final StringReader reader = new StringReader();
    final StringWriter writer = new StringWriter();
    for (int len = 0; len <= MAX_STRING_LENGTH; len++) {

        byte[] b = new byte[len];
        rnd.nextBytes(b);

        String expected = new String(b, StandardCharsets.ISO_8859_1); // reference string

        forEachSplit(bytes, (buffers) -> {
            writer.configure(expected, 0, expected.length(), false);
            boolean written = false;
            for (ByteBuffer buf : buffers) {
                int p0 = buf.position();
                written = writer.write(buf);
                buf.position(p0);
            }
            if (!written) {
                fail("please increase 'bytes' size");
            }
            reader.read(concat(buffers), chars);
            chars.flip();
            assertEquals(chars.toString(), expected);
            reader.reset();
            writer.reset();
            chars.clear();
            bytes.clear();
        });
    }
}
 
Example 5
Project: jdk8u-jdk   File: PrintSEUmlauts.java   Source Code and License Vote up 5 votes
private static void testPrintAndExit() {
    String expected = "<e4>";
    String content = "";

    File file = new File("out.ps");
    if (!DEBUG) {
        file.deleteOnExit();
    }

    try (FileInputStream stream = new FileInputStream(file)) {
        byte[] data = new byte[(int) file.length()];
        stream.read(data);
        content = new String(data, StandardCharsets.ISO_8859_1);
    } catch (IOException ex) {
        ex.printStackTrace();
    }

    if (!content.contains(expected)) {
        System.err.println("FAIL");
        if (DEBUG) {
            System.err.println("printing content");
            System.err.println(content);
        }
        throw new RuntimeException("Expected <e4> to represent '\u00e4' but not found!");
    }
    System.err.println("SUCCESS");
}
 
Example 6
Project: openjdk-jdk10   File: BinaryPrimitivesTest.java   Source Code and License Vote up 5 votes
@Test
public void stringReadChunked() {
    final int MAX_STRING_LENGTH = 16;
    final ByteBuffer bytes = ByteBuffer.allocate(MAX_STRING_LENGTH + 6);
    final CharBuffer chars = CharBuffer.allocate(MAX_STRING_LENGTH);
    final StringReader reader = new StringReader();
    final StringWriter writer = new StringWriter();
    for (int len = 0; len <= MAX_STRING_LENGTH; len++) {

        byte[] b = new byte[len];
        rnd.nextBytes(b);

        String expected = new String(b, StandardCharsets.ISO_8859_1); // reference string

        boolean written = writer
                .configure(CharBuffer.wrap(expected), 0, expected.length(), false)
                .write(bytes);
        writer.reset();

        if (!written) {
            fail("please increase 'bytes' size");
        }
        bytes.flip();

        forEachSplit(bytes, (buffers) -> {
            for (ByteBuffer buf : buffers) {
                int p0 = buf.position();
                reader.read(buf, chars);
                buf.position(p0);
            }
            chars.flip();
            assertEquals(chars.toString(), expected);
            reader.reset();
            chars.clear();
        });

        bytes.clear();
    }
}
 
Example 7
Project: instalint   File: InputFileBuilderTest.java   Source Code and License Vote up 5 votes
@Test
public void testCreateWithLanguageSet() throws IOException {
  Path path = temp.getRoot().toPath().resolve("file");
  Files.write(path, "test".getBytes(StandardCharsets.ISO_8859_1));
  ClientInputFile file = new TestClientInputFile(path, true, StandardCharsets.ISO_8859_1, "cpp");

  InputFileBuilder builder = new InputFileBuilder(langDetection, metadata);
  SonarLintInputFile inputFile = builder.create(file);

  assertThat(inputFile.language()).isEqualTo("cpp");
  verifyZeroInteractions(langDetection);
}
 
Example 8
Project: MetadataEditor   File: MetadataBlockDataPicture.java   Source Code and License Vote up 5 votes
/**
 * @return the image url if there is otherwise return an empty String
 */
public String getImageUrl()
{
    if (isImageUrl())
    {
        return new String(getImageData(), 0, getImageData().length, StandardCharsets.ISO_8859_1);
    }
    else
    {
        return "";
    }
}
 
Example 9
Project: openjdk-jdk10   File: BinaryPrimitivesTest.java   Source Code and License Vote up 5 votes
@Test
public void stringIdentity() {
    final int MAX_STRING_LENGTH = 4096;
    ByteBuffer bytes = ByteBuffer.allocate(MAX_STRING_LENGTH + 6); // it takes 6 bytes to encode string length of Integer.MAX_VALUE
    CharBuffer chars = CharBuffer.allocate(MAX_STRING_LENGTH);
    StringReader reader = new StringReader();
    StringWriter writer = new StringWriter();
    for (int len = 0; len <= MAX_STRING_LENGTH; len++) {
        for (int i = 0; i < 64; i++) {
            // not so much "test in isolation", I know... we're testing .reset() as well
            bytes.clear();
            chars.clear();

            byte[] b = new byte[len];
            rnd.nextBytes(b);

            String expected = new String(b, StandardCharsets.ISO_8859_1); // reference string

            boolean written = writer
                    .configure(CharBuffer.wrap(expected), 0, expected.length(), false)
                    .write(bytes);

            if (!written) {
                fail("please increase 'bytes' size");
            }
            bytes.flip();
            reader.read(bytes, chars);
            chars.flip();
            assertEquals(chars.toString(), expected);
            reader.reset();
            writer.reset();
        }
    }
}
 
Example 10
Project: openjdk-jdk10   File: Server.java   Source Code and License Vote up 5 votes
@Override
public void run() {
    byte[] buf = new byte[256];
    String s = "";
    try {
        while (true) {
            int n = is.read(buf);
            if (n == -1) {
                cleanup();
                return;
            }
            String s0 = new String(buf, 0, n, StandardCharsets.ISO_8859_1);
            s = s + s0;
            int i;
            while ((i=s.indexOf(CRLF)) != -1) {
                String s1 = s.substring(0, i+2);
                incoming.put(s1);
                if (i+2 == s.length()) {
                    s = "";
                    break;
                }
                s = s.substring(i+2);
            }
        }
    } catch (IOException |InterruptedException e1) {
        cleanup();
    } catch (Throwable t) {
        System.out.println("X: " + t);
        cleanup();
    }
}
 
Example 11
Project: MetadataEditor   File: ID3v1TagField.java   Source Code and License Vote up 5 votes
/**
 * Creates an instance.
 *
 * @param raw Raw byte data of the tagfield.
 * @throws UnsupportedEncodingException If the data doesn't conform "UTF-8" specification.
 */
public ID3v1TagField(final byte[] raw) throws UnsupportedEncodingException
{
    String field = new String(raw, StandardCharsets.ISO_8859_1);

    int i = field.indexOf('=');
    if (i == -1)
    {
        //Beware that ogg ID, must be capitalized and contain no space..
        this.id = "ERRONEOUS";
        this.content = field;
    }
    else
    {
        this.id = field.substring(0, i).toUpperCase();
        if (field.length() > i)
        {
            this.content = field.substring(i + 1);
        }
        else
        {
            //We have "XXXXXX=" with nothing after the "="
            this.content = "";
        }
    }
    checkCommon();
}
 
Example 12
Project: spring-boot-start-current   File: Export.java   Source Code and License Vote up 5 votes
public static String encodeName ( String name ) {
    String fileName  = name + "-" + ( DateUtils.currentTimeString() );
    String userAgent = RequestUtils.getUserAgentHeader();
    if ( StringUtils.isNotBlank( userAgent ) && userAgent.contains( "Mozilla" ) ) {
        // Chrome, Firefox, Safari etc...
        fileName = new String( fileName.getBytes() , StandardCharsets.ISO_8859_1 );
    } else {
        try {
            fileName = URLEncoder.encode( fileName , StandardCharsets.UTF_8.name() );
        } catch ( UnsupportedEncodingException e ) {
            // ignore
        }
    }
    return fileName;
}
 
Example 13
Project: EasyTransaction   File: RestRibbonEasyTransRpcConsumerImpl.java   Source Code and License Vote up 4 votes
private String encodeEasyTransHeader(Map<String, Object> header) {
	return new String(Base64.getEncoder().encode(serializer.serialization(header)), StandardCharsets.ISO_8859_1);
}
 
Example 14
Project: httrack2warc   File: HtsTxtParser.java   Source Code and License Vote up 4 votes
HtsTxtParser(InputStream txtReader) throws IOException {
    this(new BufferedReader(new InputStreamReader(txtReader, StandardCharsets.ISO_8859_1)));
}
 
Example 15
Project: httrack2warc   File: HtsDoitParser.java   Source Code and License Vote up 4 votes
HtsDoitParser(InputStream doitStream) throws IOException {
    this(new BufferedReader(new InputStreamReader(doitStream, StandardCharsets.ISO_8859_1)));
}
 
Example 16
Project: dice   File: RawByteEncoder.java   Source Code and License Vote up 4 votes
@Override
public EncoderFormat getEncoderFormat() {
    return new DefaultEncoderFormat(" ", "", System.lineSeparator(), "", System.lineSeparator(), "", StandardCharsets.ISO_8859_1, Integer.MAX_VALUE);
}
 
Example 17
Project: datarouter   File: StringByteTool.java   Source Code and License Vote up 4 votes
@Test
public void testAsciiExtensions(){
	Assert.assertTrue(unknownCharacterInt.equals(65533));

	for(int i = 0; i < 256; ++i){
		String ascii = new String(new byte[]{ByteTool.fromUnsignedInt0To255(i)}, StandardCharsets.US_ASCII);

		String latin1 = new String(new byte[]{ByteTool.fromUnsignedInt0To255(i)},
				StandardCharsets.ISO_8859_1);

		String windows1252 = new String(new byte[]{ByteTool.fromUnsignedInt0To255(i)}, Charset.forName(
				"windows-1252"));

		String utf16be = new String(new byte[]{(byte)0, ByteTool.fromUnsignedInt0To255(i)},
				StandardCharsets.UTF_16BE);

		String utf8 = new String(new byte[]{ByteTool.fromUnsignedInt0To255(i)}, StandardCharsets.UTF_8);

		if(i < 0x80){
			Assert.assertEquals(latin1, ascii);
			Assert.assertEquals(windows1252, latin1);
			Assert.assertEquals(utf16be, windows1252);
			Assert.assertEquals(utf8, utf16be);
		}else if(i < 160){
			Assert.assertEquals(unknownCharacter.toString(), ascii);// invalid octet
			Assert.assertEquals(latin1.charAt(0), i);// valid octet, but not not mapped to any character
			Assert.assertTrue(StringTool.notEmpty(windows1252));
			Assert.assertTrue(latin1.equals(utf16be));
			Assert.assertTrue(!windows1252.equals(utf16be));
			Assert.assertEquals(unknownCharacter.toString(), utf8);// utf8 will expect 2 bytes here, so our 1
																	// byte is junk
		}else{
			Assert.assertEquals(unknownCharacter.toString(), ascii);// invalid octet
			Assert.assertTrue(StringTool.notEmpty(latin1));
			Assert.assertTrue(StringTool.notEmpty(windows1252));
			Assert.assertEquals(windows1252, latin1);
			Assert.assertEquals(utf16be, windows1252);
			Assert.assertEquals(unknownCharacter.toString(), utf8);// utf8 will expect 2 bytes here, so our 1
																	// byte is junk
		}
	}
}
 
Example 18
Project: lams   File: ISO8859_14Decoder.java   Source Code and License Vote up 4 votes
ISO8859_14Decoder() {
  super(StandardCharsets.ISO_8859_1 /* fake with similar properties */, 1f, 1f);
}
 
Example 19
Project: MetadataEditor   File: ID3v1Tag.java   Source Code and License Vote up 4 votes
public Charset getEncoding()
{
    return StandardCharsets.ISO_8859_1;
}
 
Example 20
Project: MetadataEditor   File: OggVorbisTagReader.java   Source Code and License Vote up 2 votes
/**
 * Is this a Vorbis SetupHeader check
 *
 * @param headerData
 * @return true if matches vorbis setupheader
 */
public boolean isVorbisSetupHeader(byte[] headerData)
{
    String vorbis = new String(headerData, VorbisHeader.FIELD_CAPTURE_PATTERN_POS, VorbisHeader.FIELD_CAPTURE_PATTERN_LENGTH, StandardCharsets.ISO_8859_1);
    return !(headerData[VorbisHeader.FIELD_PACKET_TYPE_POS] != VorbisPacketType.SETUP_HEADER.getType() || !vorbis.equals(VorbisHeader.CAPTURE_PATTERN));
}