Determines if the supplied magic number is a valid log file header magic number
as stored in MAGIC_NUMBER

@param magicNumberBuffer The buffer containing the magic number tio compare

@return boolean true if the headers match, otherwise false
324124
private boolean validMagicNumber(byte[] magicNumberBuffer)
    {
        if (tc.isEntryEnabled())
            Tr.entry(tc, "validMagicNumber", new java.lang.Object[] { RLSUtils.toHexString(magicNumberBuffer, RLSUtils.MAX_DISPLAY_BYTES), this });

        boolean incorrectByteDetected = false;
        int currentByte = 0;

        while ((!incorrectByteDetected) && (currentByte < LogFileHeader.MAGIC_NUMBER.length))
        {
            if (magicNumberBuffer[currentByte] != LogFileHeader.MAGIC_NUMBER[currentByte])
            {
                incorrectByteDetected = true;
            }
            currentByte++;
        }

        if (tc.isEntryEnabled())
            Tr.exit(tc, "validMagicNumber", new Boolean(!incorrectByteDetected));
        return !incorrectByteDetected;
    }
1282161
private static boolean isValidHeaderMagic(OrcDataSource source)
            throws IOException
    {
        byte[] headerMagic = new byte[MAGIC.length()];
        source.readFully(0, headerMagic);

        return MAGIC.equals(Slices.wrappedBuffer(headerMagic));
    }
318141
function _caclAdler32(source,  // @arg Uint8Array - data source
                      adler) { // @arg Integer - initial value
                               // @ret Uint32 - result
    var MOD_ADLER    = 65521;
    var MAGIC_NUMBER = 5550;

    var a =  adler         & 0xffff;
    var b = (adler >>> 16) & 0xffff;

    var len = source.length;
    var i = 0;

    while (len > 0) {
        var tlen = len > MAGIC_NUMBER ? MAGIC_NUMBER : len;

        len -= tlen;

        do {
            a += source[i++];
            b += a;
        } while (--tlen);

        a %= MOD_ADLER;
        b %= MOD_ADLER;
    }
    return ((b << 16) | a) >>> 0;
}
121160
public synchronized boolean isValid() {
		if (!validState) {
			throw new InvalidStateException();
		}
		final long size = size();
		if (size == 0) {
			return true;
		}
		try {
			final long offset = (size - FOOTER_LEN);
			if (offset < 0) {
				return false;
			}
			if (offset >= offsetOutputCommited) {
				if (bufOutput.position() > 0) {
					log.warn("WARN: autoflush forced");
					flushBuffer();
				}
			}
			bufInput.clear();
			bufInput.limit(FOOTER_LEN);
			final int readed = fcInput.position(offset).read(bufInput);
			if (readed < FOOTER_LEN) {
				return false;
			}
			bufInput.flip();
			final int footer = bufInput.get(); 	// Footer (byte)
			if (footer != MAGIC_FOOT) {
				log.error("MAGIC FOOT fake=" + Integer.toHexString(footer) + " expected="
						+ Integer.toHexString(MAGIC_FOOT));
				return false;
			}
			return true;
		} catch (Exception e) {
			log.error("Exception in isValid()", e);
		}
		return false;
	}
979629
public static boolean isValidIfNumber(Object obj) {
		if (obj != null && obj instanceof Number) {
			if (obj instanceof Double) {
				if (((Double) obj).isInfinite() || ((Double) obj).isNaN()) {
					return false;
				}
			} else if (obj instanceof Float) {
				if (((Float) obj).isInfinite() || ((Float) obj).isNaN()) {
					return false;
				}
			}
		}
		return true;
	}
445129
def parse(buffer, offset = 0)
      return 0 if buffer.nil? || (buffer == '') || (buffer.length <= MAGIC_HEADER_SIZE + 2)

      # Symmetric Encryption Header
      #
      # Consists of:
      #    4 Bytes: Magic Header Prefix: @Enc
      #    1 Byte:  The version of the cipher used to encrypt the header.
      #    1 Byte:  Flags:
      #       Bit 1: Whether the data is compressed
      #       Bit 2: Whether the IV is included
      #       Bit 3: Whether the Key is included
      #       Bit 4: Whether the Cipher Name is included
      #       Bit 5: Future use
      #       Bit 6: Future use
      #       Bit 7: Future use
      #       Bit 8: Future use
      #    2 Bytes: IV Length (little endian), if included.
      #      IV in binary form.
      #    2 Bytes: Key Length (little endian), if included.
      #      Key in binary form
      #    2 Bytes: Cipher Name Length (little endian), if included.
      #      Cipher name it UTF8 text

      buffer.force_encoding(SymmetricEncryption::BINARY_ENCODING)
      header = buffer.byteslice(offset, MAGIC_HEADER_SIZE)
      return 0 unless header == MAGIC_HEADER

      offset += MAGIC_HEADER_SIZE

      # Remove header and extract flags
      self.version = buffer.getbyte(offset)
      offset      += 1

      unless cipher
        raise(
          SymmetricEncryption::CipherError,
          "Cipher with version:#{version.inspect} not found in any of the configured SymmetricEncryption ciphers"
        )
      end

      flags   = buffer.getbyte(offset)
      offset += 1

      self.compress = (flags & FLAG_COMPRESSED) != 0

      if (flags & FLAG_IV) != 0
        self.iv, offset = read_string(buffer, offset)
      else
        self.iv = nil
      end

      if (flags & FLAG_KEY) != 0
        encrypted_key, offset = read_string(buffer, offset)
        self.key              = cipher.binary_decrypt(encrypted_key)
      else
        self.key = nil
      end

      if (flags & FLAG_CIPHER_NAME) != 0
        self.cipher_name, offset = read_string(buffer, offset)
      else
        self.cipher_name = nil
      end

      if (flags & FLAG_AUTH_TAG) != 0
        self.auth_tag, offset = read_string(buffer, offset)
      else
        self.auth_tag = nil
      end

      offset
    end
368903
private boolean matchletMagicCompare(int offset, byte[] data) {
	    if (oneMatchletMagicEquals(offset, data)) {
            int nChildren = content.getInt(offset + 24);

            if (nChildren > 0) {
                int firstChildOffset = content.getInt(offset + 28);
                return matchletMagicCompareOr(nChildren, firstChildOffset, data);
            } else {
                return true;
            }
        } else {
            return false;
        }
	}
331435
function magic(buf, cb) {
  setTimeout(() => {
    const sampleLength = 24;
    const sample = buf.slice(0, sampleLength).toString('hex'); // lookup data

    const found = Object.keys(_magicDb2.default).find(it => {
      return sample.indexOf(it) != -1;
    });

    if (found) {
      cb(null, _magicDb2.default[found]);
    } else {
      cb(new Error('Magic number not found'));
    }
  }, 0);
}
1312335
public static boolean isNumber( Class clazz ) {
      return clazz != null
            && (Byte.TYPE.isAssignableFrom( clazz ) || Short.TYPE.isAssignableFrom( clazz )
                  || Integer.TYPE.isAssignableFrom( clazz ) || Long.TYPE.isAssignableFrom( clazz )
                  || Float.TYPE.isAssignableFrom( clazz ) || Double.TYPE.isAssignableFrom( clazz ) || Number.class.isAssignableFrom( clazz ));
   }
19660
public function get_byteorder($magic)
    {
        // The magic is 0x950412de
        $magic_little = (int) - 1794895138;
        $magic_little_64 = (int) 2500072158;
        // 0xde120495
        $magic_big = ((int) - 569244523) & 0xFFFFFFFF;
        if ($magic_little == $magic || $magic_little_64 == $magic) {
            return 'little';
        } elseif ($magic_big == $magic) {
            return 'big';
        } else {
            return false;
        }
    }
282023
def _identify_all(header, footer, ext=None):
    

    # Capture the length of the data
    # That way we do not try to identify bytes that don't exist
    matches = list()
    for magic_row in magic_header_array:
        start = magic_row.offset
        end = magic_row.offset + len(magic_row.byte_match)
        if end > len(header):
            continue
        if header[start:end] == magic_row.byte_match:
            matches.append(magic_row)

    for magic_row in magic_footer_array:
        start = magic_row.offset
        if footer[start:] == magic_row.byte_match:
            matches.append(magic_row)
    if not matches:
        raise PureError("Could not identify file")

    return _confidence(matches, ext)
1300361
private static ReadableLogRecord read(ByteBuffer viewBuffer, long expectedSequenceNumber, ByteBuffer sourceBuffer)
  {
    ReadableLogRecord logRecord = null;
    int absolutePosition = sourceBuffer.position() + viewBuffer.position();
    
    // Read the record magic number field.
    final byte[] magicNumberBuffer = new byte[RECORD_MAGIC_NUMBER.length];
    
    viewBuffer.get(magicNumberBuffer);        
    
    int recordLength = 0;
            
    if (Arrays.equals(magicNumberBuffer, RECORD_MAGIC_NUMBER))
    {
      long recordSequenceNumber = viewBuffer.getLong(); 
      
      if (recordSequenceNumber >= expectedSequenceNumber)
      {
        // The record sequence is consistent with the expected sequence number supplied by the
        // caller. So skip over the actual log record data in this record so that
        // we can check the tail sequence number.
        recordLength = viewBuffer.getInt();
      
        // Preserve the current byte cursor position so that we can reset back to it later. 
        // Move the byte cursor to the first byte after the record data.
        final int recordDataPosition = viewBuffer.position();                                                
        viewBuffer.position(recordDataPosition + recordLength);

        // Read the repeated record sequence number
        final long tailSequenceNumber = viewBuffer.getLong();
    
        // Because are are only looking for sequence numbers larger than expected the only assurance that we
        // have not read garbage following the magic number is that the first and tail sequence numbers are equal.
        
        // Note its still possible garbage is in the data but that can't be helped without changing the log format.
        // It will be discovered later no doubt!
        if (tailSequenceNumber == recordSequenceNumber)
        {
          // Return the buffer's pointer to the start of
          // the record's data prior to creating a new
          // ReadableLogRecord to return to the caller.
          viewBuffer.position(recordDataPosition);
          
          logRecord = new ReadableLogRecord(viewBuffer, absolutePosition, tailSequenceNumber); 
          
          // Advance the original buffer's position to the end of this record. This ensures that
          // the next ReadableLogRecord or WritableLogRecord constructed will read or write the
          // next record in the file.
          sourceBuffer.position(absolutePosition + HEADER_SIZE + recordLength);    
        }
      }
    }
    
    return logRecord;       
  }
888298
function magicBuffer(buf, cb) {
  try {
    buf = bufferUtils.toBuffer(buf);
    (0, _magic2.default)(buf, cb);
  } catch (err) {
    cb(err);
  }
}
260317
private boolean bufferLocalFileHeader() throws IOException {
        buffer.reset();
        JarEntry jarEntry = virtualJarInputStream.getNextJarEntry();

        if (jarEntry == null) { return false; }

        currentEntry = new ProcessedEntry(jarEntry, totalRead);
        processedEntries.add(currentEntry);


        bufferInt(ZipEntry.LOCSIG);    // Local file header signature
        bufferShort(10);               // Extraction version
        bufferShort(0);                // Flags
        bufferShort(ZipEntry.STORED);  // Compression type
        bufferInt(jarEntry.getTime()); // Entry time
        bufferInt(0);                  // CRC
        bufferInt(0);                  // Compressed size
        bufferInt(0);                  // Uncompressed size
        byte[] nameBytes = jarEntry.getName().getBytes("UTF8");
        bufferShort(nameBytes.length); // Entry name length
        bufferShort(0);                // Extra length
        buffer(nameBytes);
        return true;
    }
323877
def _get_file_magic_name(self, buffer):
        
        default = "Unknown"
        ftype = None

        try:
            # Magic is optional
            import magic
        except ImportError:
            return default

        try:
            # There are several implementations of magic,
            # unfortunately all called magic
            # We use this one: https://github.com/ahupp/python-magic/
            getattr(magic, "MagicException")
        except AttributeError:
            # Looks like no magic was installed
            return default

        try:
            ftype = magic.from_buffer(buffer[:1024])
        except magic.MagicError as e:
            log.exception("Error getting the magic type!")
            return default

        if not ftype:
            return default
        else:
            return self._patch_magic(buffer, ftype)
1084450
public boolean isValidStreamId(Number streamId) {
        double d = streamId.doubleValue();
        if (log.isTraceEnabled()) {
            log.trace("Checking validation for streamId {}; reservedStreams: {}; streams: {}, connection: {}", new Object[] { d, reservedStreams, streams, sessionId });
        }
        if (d <= 0 || !reservedStreams.contains(d)) {
            log.warn("Stream id: {} was not reserved in connection {}", d, sessionId);
            // stream id has not been reserved before
            return false;
        }
        if (streams.get(d) != null) {
            // another stream already exists with this id
            log.warn("Another stream already exists with this id in streams {} in connection: {}", streams, sessionId);
            return false;
        }
        if (log.isTraceEnabled()) {
            log.trace("Stream id: {} is valid for connection: {}", d, sessionId);
        }
        return true;
    }
1284431
public function isValid($my_number = '')
    {
        try {
            $phoneNumber = new PhoneNumber();
            $phoneNumber->setDebugStatus($this->DEBUG);
            $phoneNumber->setLoggerPath($this->loggerPath);
            $phoneNumber->__construct();
            $result = $phoneNumber->is_valid(trim($my_number), self::CURRENT_COUNTRY);
            $this->_debug->info(__FUNCTION__, 'Result: ' . $result);

            return $result;
        }
        catch (\Exception $e) {
            $message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
            if (function_exists('log_message')) {
                log_message('error', $message);
            }
            $this->_debug->error(__FUNCTION__, $message);

            return NULL;
        }
    }