Java Code Examples for java.nio.charset.Charset#equals()

The following examples show how to use java.nio.charset.Charset#equals() . 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: StrictLineReader.java    From candybar with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a new {@code LineReader} with the specified capacity and charset.
 *
 * @param in       the {@code InputStream} to read data from.
 * @param capacity the capacity of the buffer.
 * @param charset  the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
 *                 supported.
 * @throws NullPointerException     if {@code in} or {@code charset} is null.
 * @throws IllegalArgumentException if {@code capacity} is negative or zero
 *                                  or the specified charset is not supported.
 */
public StrictLineReader(InputStream in, int capacity, Charset charset) {
    if (in == null || charset == null) {
        throw new NullPointerException();
    }
    if (capacity < 0) {
        throw new IllegalArgumentException("capacity <= 0");
    }
    if (!(charset.equals(Util.US_ASCII))) {
        throw new IllegalArgumentException("Unsupported encoding");
    }

    this.in = in;
    this.charset = charset;
    buf = new byte[capacity];
}
 
Example 2
Source File: StrictLineReader.java    From phonegap-plugin-loading-spinner with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a new {@code LineReader} with the specified capacity and charset.
 *
 * @param in the {@code InputStream} to read data from.
 * @param capacity the capacity of the buffer.
 * @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
 *     supported.
 * @throws NullPointerException if {@code in} or {@code charset} is null.
 * @throws IllegalArgumentException if {@code capacity} is negative or zero
 *     or the specified charset is not supported.
 */
public StrictLineReader(InputStream in, int capacity, Charset charset) {
  if (in == null || charset == null) {
    throw new NullPointerException();
  }
  if (capacity < 0) {
    throw new IllegalArgumentException("capacity <= 0");
  }
  if (!(charset.equals(Util.US_ASCII))) {
    throw new IllegalArgumentException("Unsupported encoding");
  }

  this.in = in;
  this.charset = charset;
  buf = new byte[capacity];
}
 
Example 3
Source File: StrictLineReader.java    From phonegapbootcampsite with MIT License 6 votes vote down vote up
/**
 * Constructs a new {@code LineReader} with the specified capacity and charset.
 *
 * @param in the {@code InputStream} to read data from.
 * @param capacity the capacity of the buffer.
 * @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
 *     supported.
 * @throws NullPointerException if {@code in} or {@code charset} is null.
 * @throws IllegalArgumentException if {@code capacity} is negative or zero
 *     or the specified charset is not supported.
 */
public StrictLineReader(InputStream in, int capacity, Charset charset) {
  if (in == null || charset == null) {
    throw new NullPointerException();
  }
  if (capacity < 0) {
    throw new IllegalArgumentException("capacity <= 0");
  }
  if (!(charset.equals(Util.US_ASCII))) {
    throw new IllegalArgumentException("Unsupported encoding");
  }

  this.in = in;
  this.charset = charset;
  buf = new byte[capacity];
}
 
Example 4
Source File: StrictLineReader.java    From cordova-android-chromeview with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a new {@code LineReader} with the specified capacity and charset.
 *
 * @param in the {@code InputStream} to read data from.
 * @param capacity the capacity of the buffer.
 * @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
 *     supported.
 * @throws NullPointerException if {@code in} or {@code charset} is null.
 * @throws IllegalArgumentException if {@code capacity} is negative or zero
 *     or the specified charset is not supported.
 */
public StrictLineReader(InputStream in, int capacity, Charset charset) {
  if (in == null || charset == null) {
    throw new NullPointerException();
  }
  if (capacity < 0) {
    throw new IllegalArgumentException("capacity <= 0");
  }
  if (!(charset.equals(Util.US_ASCII))) {
    throw new IllegalArgumentException("Unsupported encoding");
  }

  this.in = in;
  this.charset = charset;
  buf = new byte[capacity];
}
 
Example 5
Source File: StrictLineReader.java    From CordovaYoutubeVideoPlayer with MIT License 6 votes vote down vote up
/**
 * Constructs a new {@code LineReader} with the specified capacity and charset.
 *
 * @param in the {@code InputStream} to read data from.
 * @param capacity the capacity of the buffer.
 * @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
 *     supported.
 * @throws NullPointerException if {@code in} or {@code charset} is null.
 * @throws IllegalArgumentException if {@code capacity} is negative or zero
 *     or the specified charset is not supported.
 */
public StrictLineReader(InputStream in, int capacity, Charset charset) {
  if (in == null || charset == null) {
    throw new NullPointerException();
  }
  if (capacity < 0) {
    throw new IllegalArgumentException("capacity <= 0");
  }
  if (!(charset.equals(Util.US_ASCII))) {
    throw new IllegalArgumentException("Unsupported encoding");
  }

  this.in = in;
  this.charset = charset;
  buf = new byte[capacity];
}
 
Example 6
Source File: StrictLineReader.java    From WliveTV with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a new {@code LineReader} with the specified capacity and charset.
 *
 * @param in the {@code InputStream} to read data from.
 * @param capacity the capacity of the buffer.
 * @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
 * supported.
 * @throws NullPointerException if {@code in} or {@code charset} is null.
 * @throws IllegalArgumentException if {@code capacity} is negative or zero
 * or the specified charset is not supported.
 */
public StrictLineReader(InputStream in, int capacity, Charset charset) {
	if (in == null || charset == null) {
		throw new NullPointerException();
	}
	if (capacity < 0) {
		throw new IllegalArgumentException("capacity <= 0");
	}
	if (!(charset.equals(Util.US_ASCII))) {
		throw new IllegalArgumentException("Unsupported encoding");
	}

	this.in = in;
	this.charset = charset;
	buf = new byte[capacity];
}
 
Example 7
Source File: StrictLineReader.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a new {@code LineReader} with the specified capacity and charset.
 *
 * @param in the {@code InputStream} to read data from.
 * @param capacity the capacity of the buffer.
 * @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
 * supported.
 * @throws NullPointerException if {@code in} or {@code charset} is null.
 * @throws IllegalArgumentException if {@code capacity} is negative or zero
 * or the specified charset is not supported.
 */
public StrictLineReader(InputStream in, int capacity, Charset charset) {
  if (in == null || charset == null) {
    throw new NullPointerException();
  }
  if (capacity < 0) {
    throw new IllegalArgumentException("capacity <= 0");
  }
  if (!(charset.equals(Util.US_ASCII))) {
    throw new IllegalArgumentException("Unsupported encoding");
  }

  this.in = in;
  this.charset = charset;
  buf = new byte[capacity];
}
 
Example 8
Source File: StrictLineReader.java    From reader with MIT License 6 votes vote down vote up
/**
 * Constructs a new {@code LineReader} with the specified capacity and charset.
 *
 * @param in the {@code InputStream} to read data from.
 * @param capacity the capacity of the buffer.
 * @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
 *     supported.
 * @throws NullPointerException if {@code in} or {@code charset} is null.
 * @throws IllegalArgumentException if {@code capacity} is negative or zero
 *     or the specified charset is not supported.
 */
public StrictLineReader(InputStream in, int capacity, Charset charset) {
  if (in == null || charset == null) {
    throw new NullPointerException();
  }
  if (capacity < 0) {
    throw new IllegalArgumentException("capacity <= 0");
  }
  if (!(charset.equals(Util.US_ASCII))) {
    throw new IllegalArgumentException("Unsupported encoding");
  }

  this.in = in;
  this.charset = charset;
  buf = new byte[capacity];
}
 
Example 9
Source File: StrictLineReader.java    From Android-Application-ZJB with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a new {@code LineReader} with the specified capacity and charset.
 *
 * @param in the {@code InputStream} to read data from.
 * @param capacity the capacity of the buffer.
 * @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
 * supported.
 * @throws NullPointerException if {@code in} or {@code charset} is null.
 * @throws IllegalArgumentException if {@code capacity} is negative or zero
 * or the specified charset is not supported.
 */
public StrictLineReader(InputStream in, int capacity, Charset charset) {
	if (in == null || charset == null) {
		throw new NullPointerException();
	}
	if (capacity < 0) {
		throw new IllegalArgumentException("capacity <= 0");
	}
	if (!(charset.equals(Util.US_ASCII))) {
		throw new IllegalArgumentException("Unsupported encoding");
	}

	this.in = in;
	this.charset = charset;
	buf = new byte[capacity];
}
 
Example 10
Source File: StrictLineReader.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a new {@code LineReader} with the specified capacity and charset.
 *
 * @param in the {@code InputStream} to read data from.
 * @param capacity the capacity of the buffer.
 * @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
 * supported.
 * @throws NullPointerException if {@code in} or {@code charset} is null.
 * @throws IllegalArgumentException if {@code capacity} is negative or zero
 * or the specified charset is not supported.
 */
public StrictLineReader(InputStream in, int capacity, Charset charset) {
	if (in == null || charset == null) {
		throw new NullPointerException();
	}
	if (capacity < 0) {
		throw new IllegalArgumentException("capacity <= 0");
	}
	if (!(charset.equals(Util.US_ASCII))) {
		throw new IllegalArgumentException("Unsupported encoding");
	}

	this.in = in;
	this.charset = charset;
	buf = new byte[capacity];
}
 
Example 11
Source File: StrictLineReader.java    From letv with Apache License 2.0 5 votes vote down vote up
public StrictLineReader(InputStream in, int capacity, Charset charset) {
    if (in == null || charset == null) {
        throw new NullPointerException();
    } else if (capacity < 0) {
        throw new IllegalArgumentException("capacity <= 0");
    } else if (charset.equals(Util.US_ASCII)) {
        this.in = in;
        this.charset = charset;
        this.buf = new byte[capacity];
    } else {
        throw new IllegalArgumentException("Unsupported encoding");
    }
}
 
Example 12
Source File: TimedTextVerifier.java    From ttt with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private boolean isPermittedEncoding(String name) {
    try {
        Charset cs = Charset.forName(name);
        for (Charset encoding : permittedEncodings) {
            if (encoding.equals(cs))
                return true;
        }
        return false;
    } catch (UnsupportedCharsetException e) {
        return false;
    }
}
 
Example 13
Source File: ByteSource.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public ByteSource asByteSource(Charset charset) {
  if (charset.equals(this.charset)) {
    return ByteSource.this;
  }
  return super.asByteSource(charset);
}
 
Example 14
Source File: AbstractSqlTester.java    From Quicksql with MIT License 5 votes vote down vote up
public void checkCharset(
    String expression,
    Charset expectedCharset) {
  for (String sql : buildQueries(expression)) {
    RelDataType actualType = getColumnType(sql);
    Charset actualCharset = actualType.getCharset();

    if (!expectedCharset.equals(actualCharset)) {
      fail("\n"
          + "Expected=" + expectedCharset.name() + "\n"
          + "  actual=" + actualCharset.name());
    }
  }
}
 
Example 15
Source File: ByteSource.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public ByteSource asByteSource(Charset charset) {
  if (charset.equals(this.charset)) {
    return ByteSource.this;
  }
  return super.asByteSource(charset);
}
 
Example 16
Source File: CharsetHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nullable
public static String getAsStringInOtherCharset (@Nullable final String sText,
                                                @Nonnull final Charset aCurrentCharset,
                                                @Nonnull final Charset aNewCharset)
{
  ValueEnforcer.notNull (aCurrentCharset, "CurrentCharset");
  ValueEnforcer.notNull (aNewCharset, "NewCharset");

  if (sText == null || aCurrentCharset.equals (aNewCharset))
    return sText;

  return new String (sText.getBytes (aCurrentCharset), aNewCharset);
}
 
Example 17
Source File: LoadTextUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Overwrites file with text and sets modification stamp and time stamp to the specified values.
 * <p/>
 * Normally you should not use this method.
 *
 * @param requestor            any object to control who called this method. Note that
 *                             it is considered to be an external change if {@code requestor} is {@code null}.
 *                             See {@link VirtualFileEvent#getRequestor}
 * @param newModificationStamp new modification stamp or -1 if no special value should be set @return {@code Writer}
 * @throws IOException if an I/O error occurs
 * @see VirtualFile#getModificationStamp()
 */
public static void write(@Nullable Project project, @Nonnull VirtualFile virtualFile, @Nonnull Object requestor, @Nonnull String text, long newModificationStamp) throws IOException {
  Charset existing = virtualFile.getCharset();
  Pair.NonNull<Charset, byte[]> chosen = charsetForWriting(project, virtualFile, text, existing);
  Charset charset = chosen.first;
  byte[] buffer = chosen.second;
  if (!charset.equals(existing)) {
    virtualFile.setCharset(charset);
  }
  setDetectedFromBytesFlagBack(virtualFile, buffer);

  virtualFile.setBinaryContent(buffer, newModificationStamp, -1, requestor);
}
 
Example 18
Source File: Strings.java    From sql-layer with GNU Affero General Public License v3.0 4 votes vote down vote up
public static boolean equalCharsets(Charset one, String two) {
    return one.name().equals(two) || one.equals(Charset.forName(two));
}
 
Example 19
Source File: CSSDataURL.java    From ph-css with Apache License 2.0 4 votes vote down vote up
/**
 * Full constructor
 *
 * @param aMimeType
 *        The MIME type to be used. May not be <code>null</code>. If you don't
 *        know provide the default MIME type from
 *        {@link CSSDataURLHelper#DEFAULT_MIME_TYPE}.
 * @param bBase64Encoded
 *        <code>true</code> if the data URL String representation should be
 *        Base64 encoded, <code>false</code> if not. It is recommended to set
 *        this to <code>true</code> if you have binary data like images.
 * @param aContent
 *        The content of the data URL as a byte array. May not be
 *        <code>null</code> but may be empty. This content may not be Base64
 *        encoded!
 * @param aCharset
 *        The charset to be used to encode the String. May not be
 *        <code>null</code>. The default is
 *        {@link CSSDataURLHelper#DEFAULT_CHARSET}.
 * @param sContent
 *        The String representation of the content. It must match the byte
 *        array in the specified charset. If this parameter is
 *        <code>null</code> than the String content representation is lazily
 *        created in {@link #getContentAsString()}.
 */
public CSSDataURL (@Nonnull final IMimeType aMimeType,
                   final boolean bBase64Encoded,
                   @Nonnull final byte [] aContent,
                   @Nonnull final Charset aCharset,
                   @Nullable final String sContent)
{
  ValueEnforcer.notNull (aMimeType, "MimeType");
  ValueEnforcer.notNull (aContent, "Content");
  ValueEnforcer.notNull (aCharset, "Charset");

  // Check if a charset is contained in the MIME type and if it matches the
  // provided charset
  final Charset aMimeTypeCharset = MimeTypeHelper.getCharsetFromMimeType (aMimeType);
  if (aMimeTypeCharset == null)
  {
    // No charset found in MIME type
    if (!aCharset.equals (CSSDataURLHelper.DEFAULT_CHARSET))
    {
      // append charset only if it is not the default charset
      m_aMimeType = ((MimeType) aMimeType.getClone ()).addParameter (CMimeType.PARAMETER_NAME_CHARSET,
                                                                     aCharset.name ());
    }
    else
    {
      // Default charset provided
      m_aMimeType = aMimeType;
    }
  }
  else
  {
    // MIME type has a charset - check if it matches the passed one
    if (!aMimeTypeCharset.equals (aCharset))
      throw new IllegalArgumentException ("The provided charset '" +
                                          aCharset.name () +
                                          "' differs from the charset in the MIME type: '" +
                                          aMimeTypeCharset.name () +
                                          "'");
    m_aMimeType = aMimeType;
  }
  m_bBase64Encoded = bBase64Encoded;
  m_aContent = ArrayHelper.getCopy (aContent);
  m_aCharset = aCharset;
  m_sContent = sContent;
}
 
Example 20
Source File: RpcOutputStream.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
public RpcOutputStream(RpcPerforceFile file, Charset charset, boolean isUnicodeServer,
                       boolean useLocalDigester, int filesys_utf8bom) throws IOException {
	super(file);
	if (file == null) {
		throw new NullPointerError(
				"Null RpcPerforceFile passed to RpcOutputStream constructor");
	}

	if (useLocalDigester) {
		this.localDigester = new MD5Digester();
	}
	this.fileType = file.getFileType();
	if (charset != null
			&& !(this.fileType.equals(RpcPerforceFileType.FST_XUTF8) || this.fileType.equals(RpcPerforceFileType.FST_UTF8))) {
		this.charset = isUnicodeServer && !charset.equals(CharsetDefs.UTF8) ? charset : null;
	}
	this.closed = false;
	this.file = file;
	this.lineEnding = file.getLineEnding();
	this.writeUtf8Bom = false;

	if (this.fileType != null) {
		switch (this.fileType) {
			case FST_UTF16:
			case FST_XUTF16:
				this.charset = CharsetDefs.UTF16;
			case FST_UTF8:
			case FST_XUTF8:
				// We only write a UTF8 BOM if no charset was set or it is set to a value other
				// than UTF8
				boolean addBOM = (filesys_utf8bom == 1 || (filesys_utf8bom == 2 && SystemInfo.isWindows()));
				this.writeUtf8Bom = (this.charset == null) ? addBOM : false;
			case FST_UNICODE:
			case FST_XUNICODE:
				if ((this.charset != null) &&
						(isUnicodeServer || (this.charset == CharsetDefs.UTF16))) {
					this.converter = new CharsetConverter(CharsetDefs.UTF8, this.charset);
				}
			case FST_TEXT:
			case FST_XTEXT:
				if (ClientLineEnding.needsLineEndFiltering(lineEnding)) {
					this.lineEndStream = new RpcLineEndFilterOutputStream(
							this, this.lineEnding);
				}

				break;

			case FST_GUNZIP:
			case FST_XGUNZIP:
				this.inflater = new Inflater(true);
				this.crc = new RpcCRC32Checksum();
				this.checkedOutStream = new CheckedOutputStream(new BufferedOutputStream(this), this.crc);
				this.outStream = new RpcInflaterOutputStream(this.checkedOutStream, this.inflater,
						this.localDigester);
				this.headerRead = false;
				this.footerBytes = new byte[TRAILER_SIZE];
				break;

			default:
				break;
		}
	} else {
		this.fileType = RpcPerforceFileType.FST_TEXT;
	}
}