keycloak
公開メンバ関数 | 非公開変数類 | 全メンバ一覧
org.keycloak.common.util.Base64.InputStream クラス
org.keycloak.common.util.Base64.InputStream の継承関係図
Inheritance graph
org.keycloak.common.util.Base64.InputStream 連携図
Collaboration graph

公開メンバ関数

 InputStream (java.io.InputStream in)
 
 InputStream (java.io.InputStream in, int options)
 
int read () throws java.io.IOException
 
int read (byte[] dest, int off, int len) throws java.io.IOException
 

非公開変数類

boolean encode
 
int position
 
byte [] buffer
 
int bufferLength
 
int numSigBytes
 
int lineLength
 
boolean breakLines
 
int options
 
byte [] decodabet
 

詳解

A Base64.InputStream will read data from another java.io.InputStream, given in the constructor, and encode/decode to/from Base64 notation on the fly.

参照
Base64
から
1.3

構築子と解体子

◆ InputStream() [1/2]

org.keycloak.common.util.Base64.InputStream.InputStream ( java.io.InputStream  in)
inline

Constructs a Base64.InputStream in DECODE mode.

引数
inthe java.io.InputStream from which to read data.
から
1.3
1334  {
1335  this( in, DECODE );
1336  } // end constructor
static final int DECODE
Definition: Base64.java:164

◆ InputStream() [2/2]

org.keycloak.common.util.Base64.InputStream.InputStream ( java.io.InputStream  in,
int  options 
)
inline

Constructs a Base64.InputStream in either ENCODE or DECODE mode.

Valid options:

  ENCODE or DECODE: Encode or Decode as data is read.
  DO_BREAK_LINES: break lines at 76 characters
    (only meaningful when encoding)

Example: new Base64.InputStream( in, Base64.DECODE )

引数
inthe java.io.InputStream from which to read data.
optionsSpecified options
参照
Base64::ENCODE
Base64::DECODE
Base64::DO_BREAK_LINES
から
2.0
1359  {
1360 
1361  super( in );
1362  this.options = options; // Record for later
1363  this.breakLines = (options & DO_BREAK_LINES) > 0;
1364  this.encode = (options & ENCODE) > 0;
1365  this.bufferLength = encode ? 4 : 3;
1366  this.buffer = new byte[ bufferLength ];
1367  this.position = -1;
1368  this.lineLength = 0;
1369  this.decodabet = getDecodabet(options);
1370  } // end constructor
int lineLength
Definition: Base64.java:1322
boolean encode
Definition: Base64.java:1317
int options
Definition: Base64.java:1324
static final int DO_BREAK_LINES
Definition: Base64.java:175
boolean breakLines
Definition: Base64.java:1323
static final int ENCODE
Definition: Base64.java:160
byte [] decodabet
Definition: Base64.java:1325
int bufferLength
Definition: Base64.java:1320
int position
Definition: Base64.java:1318
static final byte [] getDecodabet(int options)
Definition: Base64.java:430
byte [] buffer
Definition: Base64.java:1319

関数詳解

◆ read() [1/2]

int org.keycloak.common.util.Base64.InputStream.read ( ) throws java.io.IOException
inline

Reads enough of the input stream to convert to/from Base64 and returns the next byte.

戻り値
next byte
から
1.3

encode &&

1380  {
1381 
1382  // Do we need to get data?
1383  if( position < 0 ) {
1384  if( encode ) {
1385  byte[] b3 = new byte[3];
1386  int numBinaryBytes = 0;
1387  for( int i = 0; i < 3; i++ ) {
1388  int b = in.read();
1389 
1390  // If end of stream, b is -1.
1391  if( b >= 0 ) {
1392  b3[i] = (byte)b;
1393  numBinaryBytes++;
1394  } else {
1395  break; // out of for loop
1396  } // end else: end of stream
1397 
1398  } // end for: each needed input byte
1399 
1400  if( numBinaryBytes > 0 ) {
1401  encode3to4( b3, 0, numBinaryBytes, buffer, 0, options );
1402  position = 0;
1403  numSigBytes = 4;
1404  } // end if: got data
1405  else {
1406  return -1; // Must be end of stream
1407  } // end else
1408  } // end if: encoding
1409 
1410  // Else decoding
1411  else {
1412  byte[] b4 = new byte[4];
1413  int i = 0;
1414  for( i = 0; i < 4; i++ ) {
1415  // Read four "meaningful" bytes:
1416  int b = 0;
1417  do{ b = in.read(); }
1418  while( b >= 0 && decodabet[ b & 0x7f ] <= WHITE_SPACE_ENC );
1419 
1420  if( b < 0 ) {
1421  break; // Reads a -1 if end of stream
1422  } // end if: end of stream
1423 
1424  b4[i] = (byte)b;
1425  } // end for: each needed input byte
1426 
1427  if( i == 4 ) {
1428  numSigBytes = decode4to3( b4, 0, buffer, 0, options );
1429  position = 0;
1430  } // end if: got four characters
1431  else if( i == 0 ){
1432  return -1;
1433  } // end else if: also padded correctly
1434  else {
1435  // Must have broken out from above.
1436  throw new java.io.IOException( "Improperly padded Base64 input." );
1437  } // end
1438 
1439  } // end else: decode
1440  } // end else: get data
1441 
1442  // Got data?
1443  if( position >= 0 ) {
1444  // End of relevant data?
1445  if( position >= numSigBytes ){
1446  return -1;
1447  } // end if: got data
1448 
1449  if( encode && breakLines && lineLength >= MAX_LINE_LENGTH ) {
1450  lineLength = 0;
1451  return '\n';
1452  } // end if
1453  else {
1454  lineLength++; // This isn't important when decoding
1455  // but throwing an extra "if" seems
1456  // just as wasteful.
1457 
1458  int b = buffer[ position++ ];
1459 
1460  if( position >= bufferLength ) {
1461  position = -1;
1462  } // end if: end
1463 
1464  return b & 0xFF; // This is how you "cast" a byte that's
1465  // intended to be unsigned.
1466  } // end else
1467  } // end if: position >= 0
1468 
1469  // Else error
1470  else {
1471  throw new java.io.IOException( "Error in Base64 code reading stream." );
1472  } // end else
1473  } // end read
static int decode4to3(byte[] source, int srcOffset, byte[] destination, int destOffset, int options)
Definition: Base64.java:1030
int lineLength
Definition: Base64.java:1322
boolean encode
Definition: Base64.java:1317
static byte [] encode3to4(byte[] b4, byte[] threeBytes, int numSigBytes, int options)
Definition: Base64.java:466
int options
Definition: Base64.java:1324
boolean breakLines
Definition: Base64.java:1323
byte [] decodabet
Definition: Base64.java:1325
int bufferLength
Definition: Base64.java:1320
int position
Definition: Base64.java:1318
static final byte WHITE_SPACE_ENC
Definition: Base64.java:214
int numSigBytes
Definition: Base64.java:1321
byte [] buffer
Definition: Base64.java:1319
static final int MAX_LINE_LENGTH
Definition: Base64.java:199

◆ read() [2/2]

int org.keycloak.common.util.Base64.InputStream.read ( byte []  dest,
int  off,
int  len 
) throws java.io.IOException
inline

Calls read() repeatedly until the end of stream is reached or len bytes are read. Returns number of bytes read into array or -1 if end of stream is encountered.

引数
destarray to hold values
offoffset for array
lenmax number of bytes to read into array
戻り値
bytes read into array or -1 if end of stream is encountered.
から
1.3
1490  {
1491  int i;
1492  int b;
1493  for( i = 0; i < len; i++ ) {
1494  b = read();
1495 
1496  if( b >= 0 ) {
1497  dest[off + i] = (byte) b;
1498  }
1499  else if( i == 0 ) {
1500  return -1;
1501  }
1502  else {
1503  break; // Out of 'for' loop
1504  } // Out of 'for' loop
1505  } // end for: each byte read
1506  return i;
1507  } // end read
int read()
Definition: Base64.java:1380

メンバ詳解

◆ breakLines

boolean org.keycloak.common.util.Base64.InputStream.breakLines
private

◆ buffer

byte [] org.keycloak.common.util.Base64.InputStream.buffer
private

◆ bufferLength

int org.keycloak.common.util.Base64.InputStream.bufferLength
private

◆ decodabet

byte [] org.keycloak.common.util.Base64.InputStream.decodabet
private

◆ encode

boolean org.keycloak.common.util.Base64.InputStream.encode
private

◆ lineLength

int org.keycloak.common.util.Base64.InputStream.lineLength
private

◆ numSigBytes

int org.keycloak.common.util.Base64.InputStream.numSigBytes
private

◆ options

int org.keycloak.common.util.Base64.InputStream.options
private

◆ position

int org.keycloak.common.util.Base64.InputStream.position
private

このクラス詳解は次のファイルから抽出されました: