List of usage examples for java.io DataInputStream DataInputStream
public DataInputStream(InputStream in)
From source file:tachyon.master.EditLog.java
/** * Load one edit log./* w w w . j av a 2 s.c o m*/ * * @param info The Master Info * @param path The path of the edit log * @throws IOException */ public static void loadSingleLog(MasterInfo info, String path) throws IOException { UnderFileSystem ufs = UnderFileSystem.get(path, info.getTachyonConf()); DataInputStream is = new DataInputStream(ufs.open(path)); JsonParser parser = JsonObject.createObjectMapper().getFactory().createParser(is); while (true) { EditLogOperation op; try { op = parser.readValueAs(EditLogOperation.class); LOG.debug("Read operation: {}", op); } catch (IOException e) { // Unfortunately brittle, but Jackson rethrows EOF with this message. if (e.getMessage().contains("end-of-input")) { break; } else { throw e; } } sCurrentTId = op.mTransId; try { switch (op.mType) { case ADD_BLOCK: { info.opAddBlock(op.getInt("fileId"), op.getInt("blockIndex"), op.getLong("blockLength"), op.getLong("opTimeMs")); break; } case ADD_CHECKPOINT: { info._addCheckpoint(-1, op.getInt("fileId"), op.getLong("length"), new TachyonURI(op.getString("path")), op.getLong("opTimeMs")); break; } case CREATE_FILE: { info._createFile(op.getBoolean("recursive"), new TachyonURI(op.getString("path")), op.getBoolean("directory"), op.getLong("blockSizeByte"), op.getLong("creationTimeMs")); break; } case COMPLETE_FILE: { info._completeFile(op.get("fileId", Integer.class), op.getLong("opTimeMs")); break; } case SET_PINNED: { info._setPinned(op.getInt("fileId"), op.getBoolean("pinned"), op.getLong("opTimeMs")); break; } case RENAME: { info._rename(op.getInt("fileId"), new TachyonURI(op.getString("dstPath")), op.getLong("opTimeMs")); break; } case DELETE: { info._delete(op.getInt("fileId"), op.getBoolean("recursive"), op.getLong("opTimeMs")); break; } case CREATE_RAW_TABLE: { info._createRawTable(op.getInt("tableId"), op.getInt("columns"), op.getByteBuffer("metadata")); break; } case UPDATE_RAW_TABLE_METADATA: { info.updateRawTableMetadata(op.getInt("tableId"), op.getByteBuffer("metadata")); break; } case CREATE_DEPENDENCY: { info._createDependency(op.get("parents", new TypeReference<List<Integer>>() { }), op.get("children", new TypeReference<List<Integer>>() { }), op.getString("commandPrefix"), op.getByteBufferList("data"), op.getString("comment"), op.getString("framework"), op.getString("frameworkVersion"), op.get("dependencyType", DependencyType.class), op.getInt("dependencyId"), op.getLong("creationTimeMs")); break; } default: throw new IOException("Invalid op type " + op); } } catch (SuspectedFileSizeException e) { throw new IOException(e); } catch (BlockInfoException e) { throw new IOException(e); } catch (FileDoesNotExistException e) { throw new IOException(e); } catch (FileAlreadyExistException e) { throw new IOException(e); } catch (InvalidPathException e) { throw new IOException(e); } catch (TachyonException e) { throw new IOException(e); } catch (TableDoesNotExistException e) { throw new IOException(e); } } is.close(); ufs.close(); }
From source file:MixedRecordEnumerationExample.java
public void commandAction(Command command, Displayable displayable) { if (command == exit) { destroyApp(true);/*from ww w . j ava 2s. c om*/ notifyDestroyed(); } else if (command == start) { try { recordstore = RecordStore.openRecordStore("myRecordStore", true); } catch (Exception error) { alert = new Alert("Error Creating", error.toString(), null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); display.setCurrent(alert); } try { byte[] outputRecord; String outputString[] = { "First Record", "Second Record", "Third Record" }; int outputInteger[] = { 15, 10, 5 }; boolean outputBoolean[] = { true, false, true }; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); DataOutputStream outputDataStream = new DataOutputStream(outputStream); for (int x = 0; x < 3; x++) { outputDataStream.writeUTF(outputString[x]); outputDataStream.writeBoolean(outputBoolean[x]); outputDataStream.writeInt(outputInteger[x]); outputDataStream.flush(); outputRecord = outputStream.toByteArray(); recordstore.addRecord(outputRecord, 0, outputRecord.length); } outputStream.reset(); outputStream.close(); outputDataStream.close(); } catch (Exception error) { alert = new Alert("Error Writing", error.toString(), null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); display.setCurrent(alert); } try { StringBuffer buffer = new StringBuffer(); byte[] byteInputData = new byte[300]; ByteArrayInputStream inputStream = new ByteArrayInputStream(byteInputData); DataInputStream inputDataStream = new DataInputStream(inputStream); recordEnumeration = recordstore.enumerateRecords(null, null, false); while (recordEnumeration.hasNextElement()) { recordstore.getRecord(recordEnumeration.nextRecordId(), byteInputData, 0); buffer.append(inputDataStream.readUTF()); buffer.append("\n"); buffer.append(inputDataStream.readBoolean()); buffer.append("\n"); buffer.append(inputDataStream.readInt()); buffer.append("\n"); alert = new Alert("Reading", buffer.toString(), null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); display.setCurrent(alert); } inputStream.close(); } catch (Exception error) { alert = new Alert("Error Reading", error.toString(), null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); display.setCurrent(alert); } try { recordstore.closeRecordStore(); } catch (Exception error) { alert = new Alert("Error Closing", error.toString(), null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); display.setCurrent(alert); } if (RecordStore.listRecordStores() != null) { try { RecordStore.deleteRecordStore("myRecordStore"); recordEnumeration.destroy(); } catch (Exception error) { alert = new Alert("Error Removing", error.toString(), null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); display.setCurrent(alert); } } } }
From source file:de.ingrid.communication.authentication.BasicSchemeConnector.java
private DataInputStream createInput(Socket socket) throws IOException { InputStream inputStream = socket.getInputStream(); DataInputStream dataInput = new DataInputStream(new BufferedInputStream(inputStream, 65535)); return dataInput; }
From source file:info.fetter.logstashforwarder.protocol.LumberjackClient.java
public LumberjackClient(String keyStorePath, String server, int port, int timeout) throws IOException { this.server = server; this.port = port; try {/*from w w w. ja v a 2 s .c om*/ if (keyStorePath == null) { throw new IOException("Key store not configured"); } if (server == null) { throw new IOException("Server address not configured"); } keyStore = KeyStore.getInstance("JKS"); keyStore.load(new FileInputStream(keyStorePath), null); TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX"); tmf.init(keyStore); SSLContext context = SSLContext.getInstance("TLS"); context.init(null, tmf.getTrustManagers(), null); SSLSocketFactory socketFactory = context.getSocketFactory(); socket = new Socket(); socket.connect(new InetSocketAddress(InetAddress.getByName(server), port), timeout); socket.setSoTimeout(timeout); sslSocket = (SSLSocket) socketFactory.createSocket(socket, server, port, true); sslSocket.setUseClientMode(true); sslSocket.startHandshake(); output = new DataOutputStream(new BufferedOutputStream(sslSocket.getOutputStream())); input = new DataInputStream(sslSocket.getInputStream()); logger.info("Connected to " + server + ":" + port); } catch (IOException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.esupportail.papercut.services.PayBoxService.java
public void setDerPayboxPublicKeyFile(String derPayboxPublicKeyFile) throws NoSuchAlgorithmException, InvalidKeySpecException, IOException { org.springframework.core.io.Resource derPayboxPublicKeyRessource = new ClassPathResource( derPayboxPublicKeyFile);//w ww. j ava 2s . c o m InputStream fis = derPayboxPublicKeyRessource.getInputStream(); DataInputStream dis = new DataInputStream(fis); byte[] pubKeyBytes = new byte[fis.available()]; dis.readFully(pubKeyBytes); fis.close(); dis.close(); X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(pubKeyBytes); KeyFactory kf = KeyFactory.getInstance("RSA"); this.payboxPublicKey = kf.generatePublic(x509EncodedKeySpec); }
From source file:Version2LicenseDecoder.java
public static void main(String[] args) throws IOException, Exception { new Version2LicenseDecoder(); String lll = "AAABDA0ODAoPeNptUEtPg0AQvu+vIPG8ZsEKlmQPFda6DVAENB68rHTUbdotmQVi/71QTHykh5lM5nvMl7m4Q+2sOuOwwGHz8PomnDFnmVaOx9wrEoOtUTetPhi+ksXiJXREr3adGjckQjgNsWqBj3zKfMoCstWoLhNdg7EgNvqkFlkliryQpSA/DrzFDv7Qq2MDmdoDj9ZpKopILpIJV3Wre5gEu4n7BGhHE4+kSpsWjDI1iM9G4/FXomBMtMZ3ZbSdjm4PWpnN0M1knXX7V8D126MdDDl1SQnYA8qY31b5A5WRLKgfP0d0du8uSSkyPhRNPJ/5njcn38kHeiLjc8j5SHmH9Yey8P95XxVof60wKwITfDIxHZPgo323OEKd2FJ4BXvU7wIUIbLvXQNrkIAf4AL2Aeu4ZBRbTOA=X02dl"; String lls = "AAABckRlc2NyaXB0aW9uPUpJUkE6IENvbW1lcmNpYWwKQ3JlYXRpb25EYXRlPTIwMTMtMDYtMDcKamlyYS5MaWNlbnNlRWRpdGlvbj1FTlRFUlBSSVNFCkV2YWx1YXRpb249ZmFsc2UKamlyYS5MaWNlbnNlVHlwZU5hbWU9Q09NTUVSQ0lBTApqaXJhLmFjdGl2ZT10cnVlCmxpY2Vuc2VWZXJzaW9uPTIKTWFpbnRlbmFuY2VFeHBpcnlEYXRlPTIwOTktMDYtMDcKT3JnYW5pc2F0aW9uPWpvaWFuZGpvaW4KU0VOPVNFTi1MMjYwNjIyOQpTZXJ2ZXJJRD1CVFBRLUlDSVItNkRYQy00SDFHCmppcmEuTnVtYmVyT2ZVc2Vycz0tMQpMaWNlbnNlSUQ9TElEU0VOLUwyNjA2MjI5CkxpY2Vuc2VFeHBpcnlEYXRlPTIwOTktMDYtMDcKUHVyY2hhc2VEYXRlPTIwMTMtMDYtMDc=X02g4"; // String sll = "Description=JIRA:Commercial\nCreationDate=2013-06-07\njira.LicenseEdition=ENTERPRISE\nEvaluation=false\njira.LicenseTypeName=COMMERCIAL\njira.active=true\nlicenseVersion=2\nMaintenanceExpiryDate=2099-06-07\nOrganisation=joiandjoin\nSEN=SEN-L2606229\nServerID=BTPQ-ICIR-6DXC-4H1G\njira.NumberOfUsers=-1\nLicenseID=LIDSEN-L2606229\nLicenseExpiryDate=2099-06-07\nPurchaseDate=2013-06-07"; // String sll = "com.allenta.jira.plugins.gitlab.gitlab-listener.enterprise=true\nDescription=GitLab Listener\\: Evaluation\nNumberOfUsers=-1\nCreationDate=2015-12-29\nContactEMail=xwturing@gmail.com\nEvaluation=true\ncom.allenta.jira.plugins.gitlab.gitlab-listener.Starter=false\nlicenseVersion=2\nMaintenanceExpiryDate=2099-01-27\nOrganisation=Evaluation license\nSEN=SEN-L7030895\ncom.allenta.jira.plugins.gitlab.gitlab-listener.active=true\nLicenseExpiryDate=2099-01-27\nLicenseTypeName=COMMERCIAL\nPurchaseDate=2015-12-29\n"; // String sll = "jira.product.jira-servicedesk.active=true\njira.product.jira-servicedesk.Starter=false\nNumberOfUsers=-1\nPurchaseDate=2016-01-05\ncom.atlassian.servicedesk.active=true\nLicenseTypeName=COMMERCIAL\nLicenseExpiryDate=2099-02-03\nContactEMail=xwturing@gmail.com\nServerID=BWGW-FKTG-N1UQ-PNHH\ncom.atlassian.servicedesk.LicenseTypeName=COMMERCIAL\njira.product.jira-servicedesk.NumberOfUsers=-1\nMaintenanceExpiryDate=2099-02-03\ncom.atlassian.servicedesk.enterprise=true\nLicenseID=LIDSEN-L7059162\nSEN=SEN-L7059162\nOrganisation=Evaluation license\nCreationDate=2016-01-05\ncom.atlassian.servicedesk.numRoleCount=-1\nlicenseVersion=2\nDescription=JIRA Service Desk (Server)\\: Evaluation\nEvaluation=true"; String sll = "NumberOfUsers=-1\n" + "jira.product.jira-core.NumberOfUsers=-1\n" + "jira.NumberOfUsers=-1\n" + "PurchaseDate=2016-02-20\n" + "LicenseTypeName=COMMERCIAL\n" + "LicenseExpiryDate=2099-03-21\n" + "ContactEMail=xwturing@gmail.com\n" + "ServerID=BVDW-Q5Y0-CRXH-AI3I\n" + "jira.product.jira-core.Starter=false\n" + "jira.LicenseEdition=ENTERPRISE\n" + "jira.product.jira-core.active=true\n" + "MaintenanceExpiryDate=2099-03-21\n" + "LicenseID=LIDSEN-L7336401\n" + "SEN=SEN-L7336401\n" + "Organisation=Evaluation license\n" + "CreationDate=2016-02-20\n" + "licenseVersion=2\n" + "Description=JIRA Core (Server)\\: Evaluation\n" + "jira.active=true\n" + "jira.LicenseTypeName=COMMERCIAL\n" + "Evaluation=true"; byte[] allData = sll.getBytes(); Signature signature = Signature.getInstance("SHA1withDSA"); signature.initVerify(PUBLIC_KEY);/*from www . j a v a 2s . c o m*/ signature.update(allData); ByteArrayInputStream in = new ByteArrayInputStream(allData); DataInputStream dIn = new DataInputStream(in); int textLength = dIn.readInt(); byte[] licenseText = new byte[textLength]; dIn.read(licenseText); byte[] hash = new byte[dIn.available()]; dIn.read(hash); String result = packLicense(allData, hash); System.out.println(result); }
From source file:com.cloudera.recordbreaker.analyzer.UnknownTextSchemaDescriptor.java
void computeSchema() throws IOException { this.randId = new Random().nextInt(); LearnStructure ls = new LearnStructure(); FileSystem fs = FSAnalyzer.getInstance().getFS(); FileSystem localFS = FileSystem.getLocal(new Configuration()); Path inputPath = dd.getFilename(); File workingParserFile = File.createTempFile("textdesc", "typetree", null); File workingSchemaFile = File.createTempFile("textdesc", "schema", null); ls.inferRecordFormat(fs, inputPath, localFS, new Path(workingSchemaFile.getCanonicalPath()), new Path(workingParserFile.getCanonicalPath()), null, null, false, MAX_LINES); this.schema = Schema.parse(workingSchemaFile); DataInputStream in = new DataInputStream(localFS.open(new Path(workingParserFile.getCanonicalPath()))); try {//from w ww .j a v a 2s. com this.typeTree = InferredType.readType(in); } catch (IOException iex) { iex.printStackTrace(); throw iex; } finally { in.close(); } //System.err.println("Recovered unknowntext schema: " + schema); }
From source file:com.gisgraphy.test.GeolocTestHelper.java
public static boolean isFileContains(File file, String text) { if (file == null) { throw new IllegalArgumentException("can not check a null file"); }//from www. j a va 2 s. c o m if (!file.exists()) { throw new IllegalArgumentException("can not check a file that does not exists"); } if (!file.isFile()) { throw new IllegalArgumentException("can only check file, not directory"); } FileInputStream fstream = null; DataInputStream in = null; try { fstream = new FileInputStream(file); in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; // Read File Line By Line while ((strLine = br.readLine()) != null) { if (strLine.contains(text)) { return true; } } } catch (Exception e) {// Catch exception if any throw new IllegalArgumentException( "an exception has occured durind the assertion of " + text + " in " + file.getAbsolutePath()); } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } if (fstream != null) { try { fstream.close(); } catch (IOException e) { } } } return false; }
From source file:com.anrisoftware.prefdialog.miscswing.docks.dockingframes.layoutloader.LoadLayoutWorker.java
@Override protected void process(List<InputStream> chunks) { try {// w w w . j av a 2 s . com control.read(new DataInputStream(inputStream)); control.load(name); fireLayoutLoaded(); } catch (IOException e) { fireLayoutError(e); } synchronized (this) { notify(); } }
From source file:com.ocpsoft.pretty.faces.config.annotation.ByteCodeAnnotationFilter.java
/** * <p>// ww w. j av a 2s . com * Checks whether that supplied {@link InputStream} contains a Java class * file that might contain PrettyFaces annotations. * </p> * <p> * The caller of this method is responsible to close the supplied * {@link InputStream}. This method won't do it! * </p> * * @param classFileStream * The stream to read the class file from. * @return <code>true</code> for files that should be further checked for * annotations * @throws IOException * for any kind of IO problem */ @SuppressWarnings("unused") public boolean accept(InputStream classFileStream) throws IOException { // open a DataInputStream DataInputStream in = new DataInputStream(classFileStream); // read magic and abort if it doesn't match int magic = in.readInt(); if (magic != CLASS_FILE_MAGIC) { if (log.isDebugEnabled()) { log.debug("Magic not found! Not a valid class file!"); } return false; } // check for at least JDK 1.5 int minor = in.readUnsignedShort(); int major = in.readUnsignedShort(); if (major < 49) { // JDK 1.4 or less if (log.isTraceEnabled()) { log.trace("Not a JDK5 class! It cannot contain annotations!"); } return false; } // this values is equal to the number entries in the constants pool + 1 int constantPoolEntries = in.readUnsignedShort() - 1; // loop over all entries in the constants pool for (int i = 0; i < constantPoolEntries; i++) { // the tag to identify the record type int tag = in.readUnsignedByte(); // process record according to its type switch (tag) { case CONSTANT_Class: /* * CONSTANT_Class_info { * u1 tag; * u2 name_index; * } */ in.readUnsignedShort(); break; case CONSTANT_Fieldref: case CONSTANT_Methodref: case CONSTANT_InterfaceMethodref: /* * CONSTANT_[Fieldref|Methodref|InterfaceMethodref]_info { * u1 tag; * u2 class_index; * u2 name_and_type_index; * } */ in.readUnsignedShort(); in.readUnsignedShort(); break; case CONSTANT_String: /* * CONSTANT_String_info { * u1 tag; * u2 string_index; * } */ in.readUnsignedShort(); break; case CONSTANT_Integer: case CONSTANT_Float: /* * CONSTANT_[Integer|Float]_info { * u1 tag; * u4 bytes; * } */ in.readInt(); break; case CONSTANT_Long: case CONSTANT_Double: /* * CONSTANT_Long_info { * u1 tag; * u4 high_bytes; * u4 low_bytes; * } */ in.readLong(); /* * We must increase the constant pool index because this tag * type takes two entries */ i++; break; case CONSTANT_NameAndType: /* * CONSTANT_NameAndType_info { * u1 tag; * u2 name_index; * u2 descriptor_index; * } */ in.readUnsignedShort(); in.readUnsignedShort(); break; case CONSTANT_Utf8: /* * CONSTANT_Utf8_info { * u1 tag; * u2 length; * u1 bytes[length]; * } */ String str = in.readUTF(); // check if this string sounds interesting if (str.contains(SEARCH_STRING)) { if (log.isTraceEnabled()) { log.trace("Found PrettyFaces annotation reference in constant pool: " + str); } return true; } break; default: /* * Unknown tag! Should not happen! We will scan the class in this case. */ if (log.isDebugEnabled()) { log.debug("Unknown constant pool tag found: " + tag); } return true; } } /* * We are finished with reading the interesting parts of the class file. * We stop here because the file doesn't seem to be interesting. */ if (log.isTraceEnabled()) { log.trace("No reference to PrettyFaces annotations found!"); } return false; }