本文整理汇总了Java中com.sun.squawk.util.Arrays类的典型用法代码示例。如果您正苦于以下问题:Java Arrays类的具体用法?Java Arrays怎么用?Java Arrays使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Arrays类属于com.sun.squawk.util包,在下文中一共展示了Arrays类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: charToByteArray
import com.sun.squawk.util.Arrays; //导入依赖的package包/类
/**
* Convert a byte array to a char array
*
* @param buffer The byte array buffer
* @param offset The offset
* @param length The length
* @param enc The character encoding
* @return A new char array
* @exception UnsupportedEncodingException If the encoding is not known
*/
public static byte[] charToByteArray(char[] buffer, int offset, int length, String enc) throws UnsupportedEncodingException {
Arrays.boundsCheck(buffer.length, offset, length);
//Because most cases use ISO8859_1 encoding, we can optimize this case.
if (isISO8859_1(enc)) {
if (length < 0) {
throw new IndexOutOfBoundsException();
}
byte[] value = new byte[length];
for(int i=0; i<length; i++) {
//c = buffer[i+offset];
//value[i] = (c <= 255) ? (byte)c : (byte)'?'; TCK doesn't like seeing this '?'
value[i] = (byte)buffer[i+offset];
}
return value;
} else if (ISO8859_1_ONLY_SUPPORTED) {
throw new UnsupportedEncodingException("ISO8859_1_ONLY_SUPPORTED: " + enc);
} else {
return charToByteArray0(buffer, offset, length, enc);
}
}
示例2: strip
import com.sun.squawk.util.Arrays; //导入依赖的package包/类
/**
* Creates a stripped copy of an array of MethodMetadata. The value of <code>metadatas</code>
* is not modified. The line number tables are stripped if {@link #preserveLineNumberTables}
* has not been called. The local variable tables are stripped if {@link #preserveLineNumberTables}
* has not been called.
*
* @param metadatas the array to create a stripped copy of
* @return the stripped copy of <code>metadatas</code>
*/
static MethodMetadata[] strip(MethodMetadata[] metadatas) {
if (metadatas != null) {
if (preserveLineNumberTables || preserveLocalVariableTables) {
SquawkVector temp = new SquawkVector(metadatas.length);
for (int i = 0; i != metadatas.length; ++i) {
MethodMetadata md = metadatas[i];
if (md != null) {
temp.addElement(md.strip(preserveLineNumberTables, preserveLocalVariableTables));
}
}
if (temp.size() == 0) {
return null;
}
MethodMetadata[] result = new MethodMetadata[temp.size()];
temp.copyInto(result);
Arrays.sort(result, new MethodMetadataComparer());
return result;
}
}
return null;
}
示例3: getManifestProperty
import com.sun.squawk.util.Arrays; //导入依赖的package包/类
/**
* Gets the value of an {@link Suite#PROPERTIES_MANIFEST_RESOURCE_NAME} property embedded in the suite.
*
* @param name the name of the property whose value is to be retrieved
* @return the property value
*/
String getManifestProperty(String name) {
int index = Arrays.binarySearch(manifestProperties, name, ManifestProperty.comparer);
if (index < 0) {
// To support dynamic class loading we need to follow the same semantics as Klass.forName
// which is to look to see if we can't dynamically load a property if its not found
if (isClosed() || isPropertiesManifestResourceInstalled) {
return null;
}
// The following should automatically install the properties if there is a manifest
InputStream input = getResourceAsStream(PROPERTIES_MANIFEST_RESOURCE_NAME, null);
if (input != null) {
try {input.close();} catch (IOException e) {/*nothing*/};
}
isPropertiesManifestResourceInstalled = true;
index = Arrays.binarySearch(manifestProperties, name, ManifestProperty.comparer);
if (index < 0) {
return null;
}
}
return manifestProperties [index].value;
}
示例4: installProperty
import com.sun.squawk.util.Arrays; //导入依赖的package包/类
/**
* Installs a collection of IMlet property values into this suite.
*
* @param property IMlet property to install
*/
public void installProperty(ManifestProperty property) {
checkWrite();
// There could be more than one manifest property for a given key,
// as is the case if JAD properties are added, so take this into account
int index = Arrays.binarySearch(manifestProperties, property.name, ManifestProperty.comparer);
if (index < 0) {
/*if[ENABLE_VERBOSE]*/
if (VM.isVerbose()) {
System.out.println("[Adding property key: |" + property.name + "| value: |" + property.value + "|]");
}
/*end[ENABLE_VERBOSE]*/
System.arraycopy(manifestProperties, 0, manifestProperties = new ManifestProperty[manifestProperties.length + 1], 0, manifestProperties.length - 1);
manifestProperties[manifestProperties.length - 1] = property;
Arrays.sort(manifestProperties, ManifestProperty.comparer);
} else {
/*if[ENABLE_VERBOSE]*/
if (VM.isVerbose()) {
System.out.println("[Overwriting property key: |" + property.name + "| value: |" + property.value + "|]");
}
/*end[ENABLE_VERBOSE]*/
manifestProperties[index] = property;
}
}
示例5: traceType
import com.sun.squawk.util.Arrays; //导入依赖的package包/类
/**
* Traces a type on the operand stack or in a local variable.
*
* @param type the type to trace
* @param prefix the prefix to use if <code>isDerived</code> is true
* otherwise a prefix of spaces the same length as
* <code>prefix</code> is used instead
* @param isDerived specifies if this a type derived by the verifer or
* is specified by a stack map entry
*/
private void traceType(Klass type, String prefix, boolean isDerived) {
if (Translator.TRACING_ENABLED) {
if (!isDerived) {
char[] spaces = new char[prefix.length()];
Arrays.fill(spaces, ' ');
Tracer.trace(new String(spaces));
} else {
Tracer.trace(prefix);
}
String name = (type == null ? "-T-" : type.getInternalName());
if (isDerived) {
Tracer.traceln(" "+name);
} else {
Tracer.traceln("{"+name+"}");
}
}
}
示例6: sortFields
import com.sun.squawk.util.Arrays; //导入依赖的package包/类
/**
* Sorts an array of fields by the data size of their types in
* descending order.
*
* @param fields the array of fields to sort
*/
private void sortFields(ClassFileField[] fields) {
Arrays.sort(fields, new Comparer() {
public int compare(Object o1, Object o2) {
if (o1 == o2) {
return 0;
}
Klass t1 = ((ClassFileField)o1).getType();
Klass t2 = ((ClassFileField)o2).getType();
/*
* Sort by data size of field's type
*/
if (t1.getDataSize() < t2.getDataSize()) {
return 1;
} else if (t1.getDataSize() > t2.getDataSize()) {
return -1;
} else {
return 0;
}
}
});
}
示例7: replaceConstructor
import com.sun.squawk.util.Arrays; //导入依赖的package包/类
/**
* Substitutes the body of a given constructor method with the body of a matching method
* from a set of given replacement methods. A replacement method matches the constructor
* if it takes the same set of parameter types.
*
* @param ctor the constructor whose body is to be replaced
* @param replacements the set of methods to search for a match
* @return the new constructor once the substitution has been done
* @throws LinkageError if no substitution could be found
*/
private ClassFileMethod replaceConstructor(ClassFileMethod ctor, SquawkVector replacements) {
if (replacements != null) {
Klass[] types = ctor.getParameterTypes();
Klass[] matchTypes = new Klass[types.length + 1];
System.arraycopy(types, 0, matchTypes, 1, types.length);
matchTypes[0] = klass;
for (Enumeration e = replacements.elements(); e.hasMoreElements(); ) {
ClassFileMethod method = (ClassFileMethod)e.nextElement();
if (Arrays.equals(matchTypes, method.getParameterTypes())) {
ctor = new ClassFileMethod("<init>",
ctor.getModifiers() | Modifier.METHOD_HAS_PRAGMAS,
ctor.getReturnType(),
ctor.getParameterTypes(),
ctor.getPragmas() | PragmaException.REPLACEMENT_CONSTRUCTOR);
ctor.setCode(method.getCode());
return ctor;
}
}
}
throw new com.sun.squawk.translator.VerifyError(prefix("could not match original constructor with a replacement constructor"));
}
示例8: init
import com.sun.squawk.util.Arrays; //导入依赖的package包/类
protected final void init(INorFlashSectorState[] sectorStates) {
Arrays.sort(sectorStates, new Comparer() {
public int compare(Object a, Object b) {
Address aStart = ((INorFlashSectorState) a).getStartAddress();
Address bStart = ((INorFlashSectorState) b).getStartAddress();
if (aStart.eq(bStart)) {
return 0;
}
if (aStart.lo(bStart)) {
return -1;
}
return +1;
}
});
this.sectorStates = sectorStates;
erasedSequenceCurrentValue = 0;
}
示例9: installProperty
import com.sun.squawk.util.Arrays; //导入依赖的package包/类
/**
* Installs a collection of IMlet property values into this suite.
*
* @param property IMlet property to install
*/
public void installProperty(ManifestProperty property) {
checkWrite();
// There could be more than one manifest property for a given key,
// as is the case if JAD properties are added, so take this into account
int index = Arrays.binarySearch(manifestProperties, property.name, ManifestProperty.comparer);
if (index < 0) {
if (VM.isVerbose()) {
System.out.println("[Adding property key: |" + property.name + "| value: |" + property.value + "|]");
}
System.arraycopy(manifestProperties, 0, manifestProperties = new ManifestProperty[manifestProperties.length + 1], 0, manifestProperties.length - 1);
manifestProperties[manifestProperties.length - 1] = property;
Arrays.sort(manifestProperties, ManifestProperty.comparer);
} else {
if (VM.isVerbose()) {
System.out.println("[Overwriting property key: |" + property.name + "| value: |" + property.value + "|]");
}
manifestProperties[index] = property;
}
}
示例10: getFormattedString
import com.sun.squawk.util.Arrays; //导入依赖的package包/类
public String getFormattedString(int zoneLength)
{
if(m_updateString)
{
m_updateString = false;
if(m_stringHeader.length() + m_stringData.length() > zoneLength)
{
if(m_stringData.length() > zoneLength)
{
m_formattedString = m_stringData.substring( 0, zoneLength);
}
else
{
m_formattedString = m_stringHeader.substring(0, zoneLength - m_stringData.length()) + m_stringData;
}
}
else
{
byte[] tmp = new byte[zoneLength - (m_stringHeader.length() + m_stringData.length())];
Arrays.fill(tmp, (byte)' ');
m_formattedString = m_stringHeader + new String(tmp).concat(m_stringData);
}
}
return m_formattedString;
}
示例11: getLineTwo
import com.sun.squawk.util.Arrays; //导入依赖的package包/类
String getLineTwo()
{
byte[] tmp = new byte[m_zoneLength];
Arrays.fill(tmp, (byte)'-');
String tmpString = new String(tmp);
if(m_infoItems.size() > 1)
{
if(m_scrollPosition + 1 >= (int)m_infoItems.size())
{
tmpString = ((DisplayData)m_infoItems.elementAt(0)).getFormattedString(m_zoneLength);
}
else
{
tmpString = ((DisplayData)m_infoItems.elementAt(m_scrollPosition + 1)).getFormattedString(m_zoneLength);
}
}
return tmpString;
}
示例12: getFormattedString
import com.sun.squawk.util.Arrays; //导入依赖的package包/类
public String getFormattedString(int zoneLength)
{
if(m_updateString)
{
m_updateString = false;
String tmpString = Integer.toString(m_integerData);
if(m_integerHeader.length() + tmpString.length() > zoneLength)
{
if(tmpString.length() > zoneLength)
{
tmpString = new String( tmpString.substring( 0, (tmpString.length() - (tmpString.length() - zoneLength) - 1)));
}
m_formattedString = m_integerHeader.substring(0, zoneLength - tmpString.length()) + tmpString;
}
else
{
byte[] tmp = new byte[zoneLength - (m_integerHeader.length() + tmpString.length())];
Arrays.fill(tmp, (byte)' ');
m_formattedString = m_integerHeader + new String(tmp).concat(tmpString);
}
}
return m_formattedString;
}
示例13: getFormattedString
import com.sun.squawk.util.Arrays; //导入依赖的package包/类
public String getFormattedString(int zoneLength)
{
if(m_updateString)
{
m_updateString = false;
String tmpString = formatDecimal(m_floatData);
if(m_floatHeader.length() + tmpString.length() > zoneLength)
{
if(tmpString.length() > zoneLength)
{
tmpString = tmpString.substring( 0, (tmpString.length() - (tmpString.length() - zoneLength) - 1));
}
m_formattedString = m_floatHeader.substring(0, zoneLength - tmpString.length()) + tmpString;
}
else
{
byte[] tmp = new byte[zoneLength - (m_floatHeader.length() + tmpString.length())];
Arrays.fill(tmp, (byte)' ');
m_formattedString = m_floatHeader + new String(tmp).concat(tmpString);
}
}
return m_formattedString;
}
示例14: formatDecimal
import com.sun.squawk.util.Arrays; //导入依赖的package包/类
private String formatDecimal(double convert)
{
int exp = 10;
for(int i = 1; i < m_precision; i++)
{
exp *= 10;
}
int wholePart = (int)convert;
double decimalPart = convert - wholePart;
int convertedDecimal = (int)((decimalPart * exp) + .5);
String tmpDecimal = Integer.toString(convertedDecimal);
if(tmpDecimal.length() < m_precision)
{
byte[] extraZeros = new byte[m_precision - tmpDecimal.length()];
Arrays.fill(extraZeros, (byte)'0');
tmpDecimal = new String(extraZeros).concat(tmpDecimal);
}
return new String(Integer.toString(wholePart) + '.' + tmpDecimal);
}
示例15: write
import com.sun.squawk.util.Arrays; //导入依赖的package包/类
public void write(byte b[], int off, int len) throws IOException {
Arrays.boundsCheck(b.length, off, len);
if (len == 0) {
return;
}
int old;
if (err) {
old = VM.setStream(VM.STREAM_STDERR);
} else {
old = VM.setStream(VM.STREAM_STDOUT);
}
VM.printBytes(b, off, len);
VM.setStream(old);
}