List of usage examples for java.util Arrays equals
public static boolean equals(Object[] a, Object[] a2)
From source file:com.github.tojo.session.cookies.SignatureStrategyDefaultImplTest.java
@Test public void testSignAndPrefixSessionData() throws Exception { byte[] signedsampleSessionDataLoremIpsumAsBytes = sut.sign(sampleSessionDataLoremIpsumAsBytes); byte[] signedSessionData = sut.sign(sampleSessionDataLoremIpsumAsBytes); sut.validate(signedsampleSessionDataLoremIpsumAsBytes); sut.validate(signedSessionData);/* ww w .ja v a 2 s . c o m*/ // extract the session data and check it byte[] sessionData = ArrayUtils.subarray(signedSessionData, SIGNATURE_LENGTH, signedSessionData.length); assertTrue(Arrays.equals(sampleSessionDataLoremIpsumAsBytes, sessionData)); }
From source file:com.qwerky.tools.foldersync.Analyser.java
private boolean requireSync(File in, File out) { if (out.exists()) { try {//w w w .j a va 2s.com byte[] inmd5 = DigestUtils.md5(new FileInputStream(in)); byte[] outmd5 = DigestUtils.md5(new FileInputStream(out)); return (in.length() != out.length()) || (in.lastModified() > out.lastModified()) || !(Arrays.equals(inmd5, outmd5)); } catch (IOException ioe) { return true; } } return true; }
From source file:com.floragunn.searchguard.authentication.backend.simple.SettingsBasedAuthenticationBackend.java
@Override public User authenticate(final com.floragunn.searchguard.authentication.AuthCredentials authCreds) throws AuthException { final String user = authCreds.getUsername(); final char[] password = authCreds.getPassword(); authCreds.clear();// ww w. ja v a2s.co m String pass = settings.get(ConfigConstants.SEARCHGUARD_AUTHENTICATION_SETTINGSDB_USER + user, null); String digest = settings.get(ConfigConstants.SEARCHGUARD_AUTHENTICATION_SETTINGSDB_DIGEST, null); if (digest != null) { digest = digest.toLowerCase(); switch (digest) { case "sha": case "sha1": pass = DigestUtils.sha1Hex(pass); break; case "sha256": pass = DigestUtils.sha256Hex(pass); break; case "sha384": pass = DigestUtils.sha384Hex(pass); break; case "sha512": pass = DigestUtils.sha512Hex(pass); break; default: pass = DigestUtils.md5Hex(pass); break; } } if (pass != null && Arrays.equals(pass.toCharArray(), password)) { return new User(user); } throw new AuthException("No user " + user + " or wrong password (digest: " + (digest == null ? "plain/none" : digest) + ")"); }
From source file:com.aaasec.sigserv.cscommon.DocTypeIdentifier.java
/** * Guess the document format and return an appropriate document type string * * @param is An InputStream holding the document * @return "xml" if the document is an XML document or "pdf" if the document * is a PDF document, or else an error message. *//*from w ww .ja v a2s .co m*/ public static SigDocumentType getDocType(InputStream is) { InputStream input = null; try { input = new BufferedInputStream(is); input.mark(5); byte[] preamble = new byte[5]; int read = 0; try { read = input.read(preamble); input.reset(); } catch (IOException ex) { return SigDocumentType.Unknown; } if (read < 5) { return SigDocumentType.Unknown; } String preambleString = new String(preamble); byte[] xmlPreable = new byte[] { '<', '?', 'x', 'm', 'l' }; byte[] xmlUtf8 = new byte[] { -17, -69, -65, '<', '?' }; if (Arrays.equals(preamble, xmlPreable) || Arrays.equals(preamble, xmlUtf8)) { return SigDocumentType.XML; } else if (preambleString.equals("%PDF-")) { return SigDocumentType.PDF; } else if (preamble[0] == 'P' && preamble[1] == 'K') { ZipInputStream asics = new ZipInputStream(new BufferedInputStream(is)); ByteArrayOutputStream datafile = null; ByteArrayOutputStream signatures = null; ZipEntry entry; try { while ((entry = asics.getNextEntry()) != null) { if (entry.getName().equals("META-INF/signatures.p7s")) { signatures = new ByteArrayOutputStream(); IOUtils.copy(asics, signatures); signatures.close(); } else if (entry.getName().equalsIgnoreCase("META-INF/signatures.p7s")) { /* Wrong case */ // asics;Non ETSI compliant return SigDocumentType.Unknown; } else if (entry.getName().indexOf("/") == -1) { if (datafile == null) { datafile = new ByteArrayOutputStream(); IOUtils.copy(asics, datafile); datafile.close(); } else { // // asics;ASiC-S profile support only one data file return SigDocumentType.Unknown; } } } } catch (Exception ex) { // null;Invalid ASiC-S return SigDocumentType.Unknown; } if (datafile == null || signatures == null) { // asics;ASiC-S profile support only one data file with CAdES signature return SigDocumentType.Unknown; } // asics/cades return SigDocumentType.Unknown; } else if (preambleString.getBytes()[0] == 0x30) { // cades; return SigDocumentType.Unknown; } else { // null;Document format not recognized/handled return SigDocumentType.Unknown; } } finally { if (input != null) { try { input.close(); } catch (IOException e) { } } } }
From source file:de.tudarmstadt.ukp.dkpro.core.io.bincas.BinaryCasReader.java
@Override public void getNext(CAS aCAS) throws IOException, CollectionException { Resource res = nextFile();/*from w w w.j a v a2 s . c o m*/ InputStream is = null; try { is = CompressionUtils.getInputStream(res.getLocation(), res.getInputStream()); BufferedInputStream bis = new BufferedInputStream(is); TypeSystemImpl ts = null; // Check if this is original UIMA CAS format or DKPro Core format bis.mark(10); DataInputStream dis = new DataInputStream(bis); byte[] dkproHeader = new byte[] { 'D', 'K', 'P', 'r', 'o', '1' }; byte[] header = new byte[dkproHeader.length]; dis.read(header); // If it is DKPro Core format, read the type system if (Arrays.equals(header, dkproHeader)) { ObjectInputStream ois = new ObjectInputStream(bis); CASMgrSerializer casMgrSerializer = (CASMgrSerializer) ois.readObject(); ts = casMgrSerializer.getTypeSystem(); ts.commit(); } else { bis.reset(); } if (ts == null) { // Check if this is a UIMA binary CAS stream byte[] uimaHeader = new byte[] { 'U', 'I', 'M', 'A' }; byte[] header4 = new byte[uimaHeader.length]; System.arraycopy(header, 0, header4, 0, header4.length); if (header4[0] != 'U') { ArrayUtils.reverse(header4); } // If it is not a UIMA binary CAS stream, assume it is output from // SerializedCasWriter if (!Arrays.equals(header4, uimaHeader)) { ObjectInputStream ois = new ObjectInputStream(bis); CASCompleteSerializer serializer = (CASCompleteSerializer) ois.readObject(); deserializeCASComplete(serializer, (CASImpl) aCAS); } else { // Since there was no type system, it must be type 0 or 4 deserializeCAS(aCAS, bis); } } else { // Only format 6 can have type system information deserializeCAS(aCAS, bis, ts, null); } } catch (ResourceInitializationException e) { throw new IOException(e); } catch (ClassNotFoundException e) { throw new IOException(e); } finally { closeQuietly(is); } }
From source file:edu.oregonstate.eecs.mcplan.domains.spbj.SpBjAction.java
@Override public boolean equals(final Object obj) { final SpBjAction that = (SpBjAction) obj; return Arrays.equals(cat, that.cat); }
From source file:org.whispersystems.textsecuregcm.entities.ClientContact.java
@Override public boolean equals(Object other) { if (other == null) return false; if (!(other instanceof ClientContact)) return false; ClientContact that = (ClientContact) other; return Arrays.equals(this.token, that.token) && this.inactive == that.inactive && this.voice == that.voice && this.video == that.video && (this.relay == null ? (that.relay == null) : this.relay.equals(that.relay)); }
From source file:com.turn.ttorrent.client.io.PeerHandshakeMessage.java
@Override public void fromWire(ByteBuf in) { int pstrlen = in.readUnsignedByte(); if (pstrlen < 0 || in.readableBytes() < BASE_HANDSHAKE_LENGTH + pstrlen - 1) throw new IllegalArgumentException("Incorrect handshake message length (pstrlen=" + pstrlen + ") !"); // Check the protocol identification string protocolName = new byte[pstrlen]; in.readBytes(protocolName);//w ww . j a v a2 s . c o m if (!Arrays.equals(protocolName, BITTORRENT_PROTOCOL_IDENTIFIER)) throw new IllegalArgumentException("Unknown protocol " + new String(protocolName, Charsets.ISO_8859_1)); // Ignore reserved bytes in.readBytes(reserved); infoHash = new byte[20]; in.readBytes(infoHash); peerId = new byte[20]; in.readBytes(peerId); }
From source file:com.opengamma.analytics.financial.montecarlo.DecisionSchedule.java
@Override public boolean equals(Object obj) { if (this == obj) { return true; }//ww w .ja v a2 s . com if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } DecisionSchedule other = (DecisionSchedule) obj; if (!Arrays.equals(_decisionTime, other._decisionTime)) { return false; } if (!Arrays.equals(_impactAmount, other._impactAmount)) { return false; } if (!Arrays.equals(_impactTime, other._impactTime)) { return false; } return true; }
From source file:com.palantir.ptoss.cinch.swing.JPasswordFieldWiringHarness.java
public static Collection<Binding> bindJPasswordField(final BindableModel model, final JPasswordField pwdField, final Method getter, final Method setter) { pwdField.getDocument().addDocumentListener(new DocumentListener() { public void removeUpdate(DocumentEvent e) { updateModel();/*from ww w . j a v a 2 s.co m*/ } public void insertUpdate(DocumentEvent e) { updateModel(); } public void changedUpdate(DocumentEvent e) { updateModel(); } private void updateModel() { try { setter.invoke(model, pwdField.getPassword()); } catch (Exception ex) { Wiring.logger.error("exception in JPasswordField binding", ex); } } }); Binding binding = new Binding() { public <T extends Enum<?> & ModelUpdate> void update(T... changed) { try { char[] charArray = (char[]) getter.invoke(model); if (charArray == null) { charArray = new char[0]; } if (!Arrays.equals(charArray, pwdField.getPassword())) { pwdField.setText(String.valueOf(charArray)); } } catch (Exception ex) { Wiring.logger.error("exception in JPasswordField binding", ex); } } }; model.bind(binding); return Collections.singleton(binding); }