±Û¾´ÀÌ :±è´öÅ 1998³â 1¿ù 21ÀÏ 16:24:27
In Reply to: ³Ý½ºÄÉÀÌÇÁ4 ¿¡¼µµ À¯´ÏÄÚµå´Â ¸ðµÎ Á¦´ë·Î ³ªÅ¸³³´Ï´Ù. posted by À±°æ±¸ on 1998³â 1¿ù 21ÀÏ 11:54:08:
À©95ÀÇ ÀͽºÇ÷η¯ 4.0, ³Ý½ºÄÉÀÌÇÁ 4.0 ¸ðµÎ¿¡¼
À¯´ÏÄÚµå ¿ÜºÎ ÀÎÄÚµù ¹× À¯´ÏÄÚµåÀÇ ¸ðµç Çö´ëÇѱÛÀ» Æ÷ÇÔÇÏ´Â UTF8 ÀÎÄÚµùÀ¸·Î
µÈ À¥ ¹®¼¸¦ Á¦´ë·Î Ãâ·ÂÇØÁÝ´Ï´Ù.
ÀͽºÇ÷η¯´Â ¿©·¯°¡Áö ÀÚµ¿ÀûÀ¸·Î ÇØÁֱ⠶§¹®¿¡ ±×³É À¥ ¹®¼¸¦ ¹æ¹®Çϰųª,
ÆùÆ®¸¦ ¼±ÅÃÇØÁÖ¸é µÇ´Â µ¥,
³Ý½ºÄÉÀÌÇÁ¿¡¼´Â PreferencesÀÇ À¯´ÏÄڵ忡 ´ëÇÑ ÆùÆ®¸¦ `±¼¸²Ã¼'¿Í °°Àº
ÇÑ±Û ÆùÆ®·Î ¼³Á¤ÇÑ ÈÄ,
UTF8 ÀÎÄÚµùÀÇ ¹®¼ÀÏ °æ¿ì¿¡´Â UTF8À» ¼±ÅÃÇÏ°í,
À¯´ÏÄÚµå ¿ÜºÎ ÀÎÄÚµùÀÇ ¹®¼ÀÏ °æ¿ì¿¡´Â ¾Æ¹« ÀÎÄÚµùÀ̳ª ¼±ÅÃÇصµ
À¯´ÏÄÚµå ÇѱÛÀÌ º¸ÀÔ´Ï´Ù. (¾Æ¸¶, À¯´ÏÄÚµå ¿ÜºÎ ÀÎÄÚµùÀÇ ¹ÙÀÌÆ® ¼ø¼ Ç¥½Ä (0xfffe ȤÀº 0xfeff)
ÀÌ ÀÖÀ¸¸é ¹«Á¶°Ç À¯´ÏÄÚµå ÀÎÄÚµùÀ̶ó°í °¡Á¤ÇÏ´Â °Í °°±º¿ä.
°æ±¸´ÔÀÇ À¯´ÏÄÚµå ¹®¼¸¦ °¡Á®¿Í¼ ´ÙÀ½ ÇÁ·Î±×·¥À» »ç¿ëÇÏ¿© UTF8 ÀÎÄÚµùÀ¸·Î º¯È¯ÇÑ ÈÄ,
ÀúÀåÇÏ¿© Å×½ºÆ®Çغ¸¾Ò½À´Ï´Ù.
º»·¡ÀÇ À¯´ÏÄÚµå ¿ÜºÎ ÀÎÄÚµù ¹®¼
ÇÏÁö¸¸, ´Ù¸¥ Ç÷§Æû (ƯÈ÷, À¯´Ð½º)¿¡¼ Çö´ë ÇѱÛÀ» Ãâ·ÂÇϱⰡ °ï¶õÇÑ °ÍÀÌ °É¸²µ¹ÀÌÁö¿ä.
C:\example\i18n> java EncodingConverter2 Unicode UTF8 < unicode.html >! utf8.html
/* Classes in sun.io packages should be carefully used
since many of them are not robust esp. for exception handling
*/
import java.io.*;
import sun.io.*;
class EncodingConverter2
{
public static void main(String[] args)
throws IOException
{
ByteToCharConverter btc = ByteToCharConverter.getConverter(args[0]);
btc.setSubstitutionMode( false );
CharToByteConverter ctb = CharToByteConverter.getConverter(args[1]);
ctb.setSubstitutionMode( false );
byte[] inBuf = new byte[1];
char[] unicodes = new char[btc.getMaxCharsPerByte()];
byte[] outBuf = new byte[(btc.getMaxCharsPerByte()+1)
* ctb.getMaxBytesPerChar()];
int inOff = 0;
for(int b; (b = System.in.read()) != -1; inOff++)
{
inBuf[0] = (byte) b;
int uniLen = 0;
try
{ uniLen = btc.convert( inBuf, 0, 1, unicodes, 0, unicodes.length );
} catch( MalformedInputException ex )
{ handleBadInput( inOff );
} catch( UnknownCharacterException ex )
{ handleBadInput( inOff );
} catch( ConversionBufferFullException ex )
{ exit(ex);
}
if ( uniLen != 0 )
{
try
{ int outLen = ctb.convert( unicodes, 0, uniLen,
outBuf, 0, outBuf.length );
System.out.write(outBuf, 0, outLen);
} catch( MalformedInputException ex )
{ handleBadInput( inOff );
} catch( UnknownCharacterException ex )
{ handleBadOutput( inOff, ctb, unicodes, uniLen, outBuf );
} catch( ConversionBufferFullException ex )
{ exit(ex);
}
}
}
try
{ int uniLen = btc.flush( unicodes, 0, unicodes.length );
int outLen = ctb.convert( unicodes, 0, uniLen,
outBuf, 0, outBuf.length );
System.out.write(outBuf, 0, outLen);
} catch( MalformedInputException ex )
{ handleBadInput( inOff );
} catch( UnknownCharacterException ex )
{ handleBadInput( inOff );
} catch( ConversionBufferFullException ex )
{ exit(ex);
}
System.out.close();
}
static void handleBadOutput( int inOff, CharToByteConverter ctb,
char[] unicodes, int uniLen, byte[] outBuf )
{
System.err.println( "°æ°í: À§Ä¡ " + inOff
+ "ÀÇ ÀÔ·Â ¹®ÀÚ¸¦ Ç¥ÇöÇÒ ¼ö ¾ø´Â Ãâ·Â ÀÎÄÚµù." );
try
{ ctb.setSubstitutionMode( true );
int outLen = ctb.convert( unicodes, 0, uniLen,
outBuf, 0, outBuf.length );
System.out.write(outBuf, 0, outLen);
ctb.setSubstitutionMode( false );
} catch( Exception ex )
{ exit( ex );
}
}
static void handleBadInput( int inOff )
{
System.err.println( "¿À·ù: À§Ä¡ " + inOff
+ "¿¡ À߸øµÈ ÀÔ·Â ¹®ÀÚ·Î ÁߴܵÊ." );
System.exit(-1);
}
static void exit( Throwable ex )
{ System.err.println( "¿À·ù: ±â´ëµÇÁö ¾Ê´Â ¿À·ù·Î ÁߴܵÊ. ¿øÀÎ -> " + ex );
System.exit(-1);
}
}