java.nio.charset.Charset#equals ( )源码实例Demo

下面列出了java.nio.charset.Charset#equals ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * 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];
}
 
源代码2 项目: candybar   文件: StrictLineReader.java
/**
 * 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];
}
 
源代码3 项目: phonegapbootcampsite   文件: StrictLineReader.java
/**
 * 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];
}
 
/**
 * 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];
}
 
/**
 * 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];
}
 
源代码6 项目: WliveTV   文件: StrictLineReader.java
/**
 * 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];
}
 
/**
 * 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];
}
 
/**
 * 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];
}
 
源代码9 项目: reader   文件: StrictLineReader.java
/**
 * 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];
}
 
源代码10 项目: UltimateAndroid   文件: StrictLineReader.java
/**
 * 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];
}
 
源代码11 项目: consulo   文件: LoadTextUtil.java
/**
 * 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);
}
 
源代码12 项目: ph-commons   文件: CharsetHelper.java
@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);
}
 
源代码13 项目: codebuff   文件: ByteSource.java
@Override
public ByteSource asByteSource(Charset charset) {
  if (charset.equals(this.charset)) {
    return ByteSource.this;
  }
  return super.asByteSource(charset);
}
 
源代码14 项目: Quicksql   文件: AbstractSqlTester.java
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());
    }
  }
}
 
源代码15 项目: codebuff   文件: ByteSource.java
@Override
public ByteSource asByteSource(Charset charset) {
  if (charset.equals(this.charset)) {
    return ByteSource.this;
  }
  return super.asByteSource(charset);
}
 
源代码16 项目: ttt   文件: TimedTextVerifier.java
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;
    }
}
 
源代码17 项目: letv   文件: StrictLineReader.java
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");
    }
}
 
源代码18 项目: sql-layer   文件: Strings.java
public static boolean equalCharsets(Charset one, String two) {
    return one.name().equals(two) || one.equals(Charset.forName(two));
}
 
源代码19 项目: ph-css   文件: CSSDataURL.java
/**
 * 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;
}
 
源代码20 项目: p4ic4idea   文件: RpcOutputStream.java
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;
	}
}