📄 saputf8bytetocharconverter.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: SAPUTF8ByteToCharConverter.java
package com.sap.mw.jco.util;
// Referenced classes of package com.sap.mw.jco.util:
// BasicSAPConverter, SAPByteToCharConverter
public class SAPUTF8ByteToCharConverter extends BasicSAPConverter
implements SAPByteToCharConverter
{
protected SAPUTF8ByteToCharConverter(String charEncoding)
{
super(charEncoding);
super.codepageType = 1;
}
public int convert(byte in[], int inBeginIndex, int inEndIndex, char out[], int outBeginIndex, int outEndIndex)
{
if(in == null)
return 0;
if(inBeginIndex < 0)
return 0;
if(inBeginIndex >= in.length)
return 0;
if(inEndIndex >= in.length)
inEndIndex = in.length - 1;
if(inBeginIndex > inEndIndex)
return 0;
if(out == null)
return 0;
if(outBeginIndex < 0)
return 0;
if(outBeginIndex >= out.length)
return 0;
if(outEndIndex >= out.length)
outEndIndex = out.length - 1;
if(outBeginIndex > outEndIndex)
return 0;
int inIndex = inBeginIndex;
int outIndex = outBeginIndex;
while(inIndex <= inEndIndex && outIndex <= outEndIndex)
{
if(in[inIndex] >= 0)
{
out[outIndex++] = (char)in[inIndex++];
continue;
}
switch(in[inIndex] & 0xf0)
{
default:
break;
case 192:
case 208:
if(inIndex + 1 > inEndIndex)
{
inIndex = inEndIndex;
break;
}
if((in[inIndex + 1] & 0xc0) != 128)
break;
out[outIndex++] = (char)((in[inIndex] & 0x1f) << 6 | in[inIndex + 1] & 0x3f);
inIndex += 2;
continue;
case 224:
if(inIndex + 2 > inEndIndex)
{
inIndex = inEndIndex;
break;
}
if((in[inIndex + 1] & 0xc0) != 128 || (in[inIndex + 2] & 0xc0) != 128)
break;
out[outIndex++] = (char)(((in[inIndex] & 0xf) << 6 | in[inIndex + 1] & 0x3f) << 6 | in[inIndex + 2] & 0x3f);
inIndex += 3;
continue;
case 240:
int charid;
if((in[inIndex] & 8) == 0)
{
if(inIndex + 3 > inEndIndex)
{
inIndex = inEndIndex;
break;
}
if((in[inIndex + 1] & 0xc0) != 128 || (in[inIndex + 2] & 0xc0) != 128 || (in[inIndex + 3] & 0xc0) != 128)
break;
charid = (((in[inIndex] & 7) << 6 | in[inIndex + 1] & 0x3f) << 6 | in[inIndex + 2] & 0x3f) << 6 | in[inIndex + 3] & 0x3f;
inIndex += 4;
} else
if((in[inIndex] & 4) == 0)
{
if(inIndex + 4 > inEndIndex)
{
inIndex = inEndIndex;
break;
}
if((in[inIndex + 1] & 0xc0) != 128 || (in[inIndex + 2] & 0xc0) != 128 || (in[inIndex + 3] & 0xc0) != 128 || (in[inIndex + 4] & 0xc0) != 128)
break;
charid = ((((in[inIndex] & 3) << 6 | in[inIndex + 1] & 0x3f) << 6 | in[inIndex + 2] & 0x3f) << 6 | in[inIndex + 3] & 0x3f) << 6 | in[inIndex + 4] & 0x3f;
inIndex += 5;
} else
{
if((in[inIndex] & 2) != 0)
break;
if(inIndex + 5 > inEndIndex)
{
inIndex = inEndIndex;
break;
}
if((in[inIndex + 1] & 0xc0) != 128 || (in[inIndex + 2] & 0xc0) != 128 || (in[inIndex + 3] & 0xc0) != 128 || (in[inIndex + 4] & 0xc0) != 128 || (in[inIndex + 5] & 0xc0) != 128)
break;
charid = (((((in[inIndex] & 1) << 6 | in[inIndex + 1] & 0x3f) << 6 | in[inIndex + 2] & 0x3f) << 6 | in[inIndex + 3] & 0x3f) << 6 | in[inIndex + 4] & 0x3f) << 6 | in[inIndex + 5] & 0x3f;
inIndex += 6;
}
if(charid < 0x10000)
out[outIndex++] = (char)charid;
else
if(charid < 0x11000)
{
if(outIndex == outEndIndex)
{
inIndex = inEndIndex + 1;
} else
{
charid -= 0x10000;
out[outIndex++] = (char)(charid >> 10 & 0x3ff | 0xd800);
out[outIndex++] = (char)(charid & 0x3ff | 0xdc00);
}
} else
{
out[outIndex++] = '#';
}
continue;
}
out[outIndex++] = '#';
for(inIndex++; inIndex <= inEndIndex && (in[inIndex] & 0xc0) == 128; inIndex++);
}
return outIndex - outBeginIndex;
}
public char[] convert(byte in[], int inBeginIndex, int inEndIndex)
{
if(in == null)
return new char[0];
if(inBeginIndex < 0)
return new char[0];
if(inBeginIndex >= in.length)
return new char[0];
if(inEndIndex >= in.length)
inEndIndex = in.length - 1;
if(inBeginIndex > inEndIndex)
{
return new char[0];
} else
{
int outLength = outLength(in, inBeginIndex, inEndIndex);
char out[] = new char[outLength];
convert(in, inBeginIndex, inEndIndex, out, 0, outLength - 1);
return out;
}
}
public char[] convert(byte in[])
{
if(in == null)
{
return new char[0];
} else
{
int outLength = outLength(in, 0, in.length - 1);
char out[] = new char[outLength];
convert(in, 0, in.length - 1, out, 0, outLength - 1);
return out;
}
}
public int outLength(byte in[], int inBeginIndex, int inEndIndex)
{
if(in == null)
return 0;
if(inBeginIndex < 0)
return 0;
if(inBeginIndex >= in.length)
return 0;
if(inEndIndex >= in.length)
inEndIndex = in.length - 1;
if(inBeginIndex > inEndIndex)
return 0;
int outLength = 0;
int inIndex = inBeginIndex;
while(inIndex <= inEndIndex)
{
if(in[inIndex] >= 0)
{
outLength++;
inIndex++;
continue;
}
switch(in[inIndex] & 0xf0)
{
default:
break;
case 192:
case 208:
if(inIndex + 1 > inEndIndex)
{
inIndex = inEndIndex;
break;
}
if((in[inIndex + 1] & 0xc0) != 128)
break;
outLength++;
inIndex += 2;
continue;
case 224:
if(inIndex + 2 > inEndIndex)
{
inIndex = inEndIndex;
break;
}
if((in[inIndex + 1] & 0xc0) != 128 || (in[inIndex + 2] & 0xc0) != 128)
break;
outLength++;
inIndex += 3;
continue;
case 240:
int charid;
if((in[inIndex] & 8) == 0)
{
if(inIndex + 3 > inEndIndex)
{
inIndex = inEndIndex;
break;
}
if((in[inIndex + 1] & 0xc0) != 128 || (in[inIndex + 2] & 0xc0) != 128 || (in[inIndex + 3] & 0xc0) != 128)
break;
charid = (((in[inIndex] & 7) << 6 | in[inIndex + 1] & 0x3f) << 6 | in[inIndex + 2] & 0x3f) << 6 | in[inIndex + 3] & 0x3f;
inIndex += 4;
} else
if((in[inIndex] & 4) == 0)
{
if(inIndex + 4 > inEndIndex)
{
inIndex = inEndIndex;
break;
}
if((in[inIndex + 1] & 0xc0) != 128 || (in[inIndex + 2] & 0xc0) != 128 || (in[inIndex + 3] & 0xc0) != 128 || (in[inIndex + 4] & 0xc0) != 128)
break;
charid = ((((in[inIndex] & 3) << 6 | in[inIndex + 1] & 0x3f) << 6 | in[inIndex + 2] & 0x3f) << 6 | in[inIndex + 3] & 0x3f) << 6 | in[inIndex + 4] & 0x3f;
inIndex += 5;
} else
{
if((in[inIndex] & 2) != 0)
break;
if(inIndex + 5 > inEndIndex)
{
inIndex = inEndIndex;
break;
}
if((in[inIndex + 1] & 0xc0) != 128 || (in[inIndex + 2] & 0xc0) != 128 || (in[inIndex + 3] & 0xc0) != 128 || (in[inIndex + 4] & 0xc0) != 128 || (in[inIndex + 5] & 0xc0) != 128)
break;
charid = (((((in[inIndex] & 1) << 6 | in[inIndex + 1] & 0x3f) << 6 | in[inIndex + 2] & 0x3f) << 6 | in[inIndex + 3] & 0x3f) << 6 | in[inIndex + 4] & 0x3f) << 6 | in[inIndex + 5] & 0x3f;
inIndex += 6;
}
if(charid < 0x10000)
outLength++;
else
if(charid < 0x11000)
outLength += 2;
else
outLength++;
continue;
}
outLength++;
for(inIndex++; inIndex <= inEndIndex && (in[inIndex] & 0xc0) == 128; inIndex++);
}
return outLength;
}
public int outLength(byte in[])
{
if(in == null)
return 0;
else
return outLength(in, 0, in.length - 1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -