List of usage examples for java.io DataInputStream DataInputStream
public DataInputStream(InputStream in)
From source file:com.videobox.web.util.dwr.AutoAnnotationDiscoveryContainer.java
private void handleClass(InputStream istream, StringBuilder sb) throws IOException { DataInputStream dstream = new DataInputStream(istream); ClassFile cf = new ClassFile(dstream); AnnotationsAttribute visible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.visibleTag); if (visible != null) { for (Annotation ann : visible.getAnnotations()) { // logger.info( cf.getName() + " contains @" + ann.getTypeName() ); if (ann.getTypeName().equals(RemoteProxy.class.getName())) { sb.append(cf.getName() + ","); } else if (ann.getTypeName().equals(DataTransferObject.class.getName())) { dataConverterObjects.add(cf.getName()); // addDataConverterObject(cf); }//from w w w . j a va2 s . c om } } }
From source file:com.bahmanm.karun.PacmanConfHelper.java
/** * Extracts valuable info from 'pacman.conf'. *///from w w w .j a v a 2 s .c om private void extractInfo() throws FileNotFoundException, IOException { FileInputStream fis = new FileInputStream(confPath); DataInputStream dis = new DataInputStream(fis); BufferedReader br = new BufferedReader(new InputStreamReader(dis)); String line; try { while ((line = br.readLine()) != null) { line = StringUtils.normalizeSpace(line); if (line.startsWith("#")) { continue; } else if (line.startsWith("[") && line.endsWith("]")) { String section = line.substring(1, line.length() - 1); if (!section.equals("options")) { repos.add(section); } } else if (line.startsWith("DBPath")) { dbPath = line.split("=")[1].trim(); } else if (line.startsWith("CacheDir")) { cacheDir = line.split("=")[1].trim(); } } } catch (IOException ex) { Logger.getLogger(PacmanConfHelper.class.getName()).log(Level.SEVERE, null, ex); try { br.close(); dis.close(); fis.close(); } catch (IOException ioex) { throw new IOException("Error closing stream or reader: " + ioex.getMessage()); } } }
From source file:LCModels.MessageListener.java
public void run() { /* Keep Thread running */ while (true) { try {//from w w w . java 2 s . co m /* Accept connection on server */ Socket serverSocket = server.accept(); /* DataInputStream to get message sent by client program */ DataInputStream in = new DataInputStream(serverSocket.getInputStream()); /* We are receiving message in JSON format from client. Parse String to JSONObject */ JSONObject clientMessage = new JSONObject(in.readUTF()); /* Flag to check chat window is opened for user that sent message */ boolean flagChatWindowOpened = false; /* Reading Message and Username from JSONObject */ String userName = clientMessage.get("Username").toString(); String message = clientMessage.getString("Message").toString(); /* Get list of Frame/Windows opened by mainFrame.java */ for (Frame frame : Frame.getFrames()) { /* Check Frame/Window is opened for user */ if (frame.getTitle().equals(userName)) { /* Frame/ Window is already opened */ flagChatWindowOpened = true; /* Get instance of ChatWindow */ ChatWindowUI chatWindow = (ChatWindowUI) frame; /* Get previous messages from TextArea */ String previousMessage = chatWindow.getMessageArea().getText(); /* Set message to TextArea with new message */ chatWindow.getMessageArea().setText(previousMessage + "\n" + userName + ": " + message); } } /* ChatWindow is not open for user sent message to server */ if (!flagChatWindowOpened) { /* Create an Object of ChatWindow */ ChatWindowUI chatWindow = new ChatWindowUI(); /** * We are setting title of window to identify user for next * message we gonna receive You can set hidden value in * ChatWindow.java file. */ chatWindow.setTitle(userName); /* Set message to TextArea */ chatWindow.getMessageArea().setText(message); /* Make ChatWindow visible */ chatWindow.setVisible(true); } /* Get DataOutputStream of client to repond */ DataOutputStream out = new DataOutputStream(serverSocket.getOutputStream()); /* Send response message to client */ out.writeUTF("Received from " + clientMessage.get("Username").toString()); } catch (Exception e) { e.printStackTrace(); } } }
From source file:edu.cornell.med.icb.goby.compression.HybridChunkCodec1.java
@Override public Message decode(final byte[] bytes) throws IOException { final DataInputStream completeChunkData = new DataInputStream(new FastByteArrayInputStream(bytes)); final int compressedSize = completeChunkData.readInt(); final int storedChecksum = completeChunkData.readInt(); final byte[] compressedBytes = new byte[compressedSize]; final int read = completeChunkData.read(compressedBytes, 0, compressedSize); assert read == compressedSize : "read size must match recorded size."; crc32.reset();/*from w ww . ja v a2s .co m*/ crc32.update(compressedBytes); final int computedChecksum = (int) crc32.getValue(); if (computedChecksum != storedChecksum) { throw new InvalidChecksumException(); } final int bytesLeft = bytes.length - 4 - compressedSize - 4; final byte[] leftOver = new byte[bytesLeft]; // 8 is the number of bytes to encode the length of the compressed chunk, plus // the number of bytes to encode the checksum. System.arraycopy(bytes, 8 + compressedSize, leftOver, 0, bytesLeft); final Message reducedProtoBuff = gzipCodec.decode(leftOver); if (reducedProtoBuff == null) { return null; } return handler.decompressCollection(reducedProtoBuff, compressedBytes); }
From source file:com.googlecode.onevre.utils.ServerClassLoader.java
/** * Creates a new ServerClassLoader/* w w w.j ava 2s . c o m*/ * @param parent The parent class loader * @param localCacheDirectory The directory to cache files to * @param remoteServer The URL of the remote server */ public ServerClassLoader(ClassLoader parent, File localCacheDirectory, URL remoteServer) { super(parent); this.localCacheDirectory = localCacheDirectory; this.localLibDirectory = new File(localCacheDirectory, LIB_DIR); File versionFile = new File(localCacheDirectory, "Version"); boolean versionCorrect = false; if (!localCacheDirectory.exists()) { localCacheDirectory.mkdirs(); } else { if (versionFile.exists()) { try { BufferedReader reader = new BufferedReader(new FileReader(versionFile)); String version = reader.readLine(); reader.close(); versionCorrect = Defaults.PAG_VERSION.equals(version); log.info(version + " == " + Defaults.PAG_VERSION + " = " + versionCorrect); } catch (IOException e) { // Do Nothing } } try { FileInputStream input = new FileInputStream(new File(localCacheDirectory, INDEX)); DataInputStream cacheFile = new DataInputStream(input); FileChannel channel = input.getChannel(); while (channel.position() < channel.size()) { URL url = new URL(cacheFile.readUTF()); String file = cacheFile.readUTF(); if (versionCorrect && url.getHost().equals(remoteServer.getHost()) && (url.getPort() == remoteServer.getPort())) { File jar = new File(localCacheDirectory, file); if (jar.exists()) { indexJar(url, jar); CHECKED.put(url, true); } } } input.close(); } catch (FileNotFoundException e) { // Do Nothing - cache will be recreated later } catch (IOException e) { // Do Nothing - as above } } localLibDirectory.mkdirs(); try { PrintWriter writer = new PrintWriter(versionFile); writer.println(Defaults.PAG_VERSION); writer.close(); } catch (IOException e) { e.printStackTrace(); } this.remoteServer = remoteServer; }
From source file:fr.insalyon.creatis.vip.datamanager.server.rpc.FileDownloadServiceImpl.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { User user = (User) req.getSession().getAttribute(CoreConstants.SESSION_USER); String operationId = req.getParameter("operationid"); if (user != null && operationId != null && !operationId.isEmpty()) { try {// ww w . jav a 2 s . c o m GRIDAPoolClient client = CoreUtil.getGRIDAPoolClient(); Operation operation = client.getOperationById(operationId); File file = new File(operation.getDest()); if (file.isDirectory()) { file = new File(operation.getDest() + "/" + FilenameUtils.getName(operation.getSource())); } int length = 0; ServletOutputStream op = resp.getOutputStream(); ServletContext context = getServletConfig().getServletContext(); String mimetype = context.getMimeType(file.getName()); logger.info("(" + user.getEmail() + ") Downloading '" + file.getAbsolutePath() + "'."); resp.setContentType((mimetype != null) ? mimetype : "application/octet-stream"); resp.setContentLength((int) file.length()); resp.setHeader("Content-Disposition", "attachment; filename=\"" + file.getName() + "\""); byte[] bbuf = new byte[4096]; DataInputStream in = new DataInputStream(new FileInputStream(file)); while ((in != null) && ((length = in.read(bbuf)) != -1)) { op.write(bbuf, 0, length); } in.close(); op.flush(); op.close(); } catch (GRIDAClientException ex) { logger.error(ex); } } }
From source file:TripleDES.java
/** Read a TripleDES secret key from the specified file */ public static SecretKey readKey(File f) throws IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException { // Read the raw bytes from the keyfile DataInputStream in = new DataInputStream(new FileInputStream(f)); byte[] rawkey = new byte[(int) f.length()]; in.readFully(rawkey);//from w ww . j a v a 2s . co m in.close(); // Convert the raw bytes to a secret key like this DESedeKeySpec keyspec = new DESedeKeySpec(rawkey); SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("DESede"); SecretKey key = keyfactory.generateSecret(keyspec); return key; }
From source file:org.jboss.capedwarf.tools.BulkLoader.java
private static void doDump(Arguments args) { String url = getUrl(args);/* w ww .ja v a 2s. c o m*/ String filename = getFilename(args); int packetSize = getPacketSize(args); File file = new File(filename); if (file.exists()) { System.out.println("WARNING: File " + filename + " already exists!"); System.exit(1); } System.out.println("Dumping data from " + url + " to " + filename + " in packets of size " + packetSize); DumpFileFacade dumpFileFacade = new DumpFileFacade(file); try { DefaultHttpClient client = new DefaultHttpClient(new SingleClientConnManager()); try { HttpGet get = new HttpGet(url); get.getParams().setParameter("action", "dump"); System.out.println("Downloading packet of " + packetSize + " entities"); HttpResponse response = client.execute(get); DataInputStream in = new DataInputStream(response.getEntity().getContent()); while (true) { byte[] idBytes = readArray(in); if (idBytes == null) { break; } byte[] entityPbBytes = readArray(in); byte[] sortKeyBytes = readArray(in); dumpFileFacade.add(idBytes, entityPbBytes, sortKeyBytes); } } catch (IOException e) { throw new RuntimeException(e); } } finally { dumpFileFacade.close(); } }
From source file:com.cedarsoft.crypt.CertTest.java
@Test public void testKey() throws Exception { InputStream inStream = new DataInputStream(getClass().getResource("/test.der").openStream()); byte[] keyBytes = new byte[inStream.available()]; inStream.read(keyBytes);/*from w w w . j av a 2 s . c o m*/ inStream.close(); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); // decipher private key PKCS8EncodedKeySpec privSpec = new PKCS8EncodedKeySpec(keyBytes); RSAPrivateKey privKey = (RSAPrivateKey) keyFactory.generatePrivate(privSpec); assertNotNull(privKey); Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.ENCRYPT_MODE, privKey); byte[] bytes = cipher.doFinal(PLAINTEXT.getBytes()); assertEquals(SCRAMBLED, new String(Base64.encodeBase64(bytes))); }