IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Collection et Stream Java Discussion :

Injecter une date GMT


Sujet :

Collection et Stream Java

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    201
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 201
    Points : 150
    Points
    150
    Par défaut Injecter une date GMT
    Bonjour à tous,

    Je ne cherche pas vraiment à apprendre JAVA, mais je suis face à un petit problème qui risque de me prendre pas mal de temps sans votre aide...

    J'ai une source (autorisée) d'un fichier qui permet actuellement d'injecter du texte depuis un fichier texte dans un flux.

    Moi je voudrais injecter l'heure GMT à la place du fichier texte...

    Aussi, si vous pouviez fortement m'orienter, ce serais avec plaisir que j'accepterais... Vu que je ne connais rien a JAVA...


    D'avance merci

    tepaze
    Fichiers attachés Fichiers attachés

  2. #2
    Expert éminent
    Avatar de fred1599
    Homme Profil pro
    Lead Dev Python
    Inscrit en
    Juillet 2006
    Messages
    3 823
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Lead Dev Python
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Juillet 2006
    Messages : 3 823
    Points : 7 119
    Points
    7 119
    Par défaut
    Je suis débutant en java, aussi je découvre le langage avec plaisir...

    Mais c'est pas clair dans tes difficultés, ton problème est dans l'injection d'une chaîne de caractères dans un flux ou comment avoir l'heure GMT ?
    Celui qui trouve sans chercher est celui qui a longtemps cherché sans trouver.(Bachelard)
    La connaissance s'acquiert par l'expérience, tout le reste n'est que de l'information.(Einstein)

  3. #3
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    201
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 201
    Points : 150
    Points
    150
    Par défaut
    Autant pour moi Fred,

    Le fichier joint permet l'injection de texte, depuis un fichier texte, dans un flux.

    Pour ma part je voudrais :
    - Injecter l'heure GMT à la place du texte
    ou
    - injecter une chaine depuis une url (genre appel url et le retour est injecté...)

    Est ce plus clair ?

  4. #4
    Expert éminent
    Avatar de fred1599
    Homme Profil pro
    Lead Dev Python
    Inscrit en
    Juillet 2006
    Messages
    3 823
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Lead Dev Python
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Juillet 2006
    Messages : 3 823
    Points : 7 119
    Points
    7 119
    Par défaut
    Est ce plus clair ?
    Désolé mais non

    Injecter l'heure GMT à la place du texte

    • L'heure GMT, tu arrives à la récupérer ?
    • Quel type de flux parles-tu ?


    Désolé, mais je ne lis pas les pièces jointes, c'est contre ma religion
    Celui qui trouve sans chercher est celui qui a longtemps cherché sans trouver.(Bachelard)
    La connaissance s'acquiert par l'expérience, tout le reste n'est que de l'information.(Einstein)

  5. #5
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    201
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 201
    Points : 150
    Points
    150
    Par défaut
    En l'occurrence c'est un flux vidéo.

    Je ne sais pas du tout utiliser JAVA, donc je ne récupère rien pour le moment.

    Voici le code de la pièce jointe afin que cela soit, je l'espere, plus comprehensible.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    package com.wowza.wms.plugin.closedcaption.test;
     
    import java.io.*;
    import java.util.*;
     
    import com.wowza.util.*;
    import com.wowza.wms.amf.*;
    import com.wowza.wms.application.IApplicationInstance;
    import com.wowza.wms.media.model.*;
    import com.wowza.wms.module.ModuleBase;
    import com.wowza.wms.stream.*;
     
    public class ModulePublishOnTextData extends ModuleBase
    {
    	class OnTextData
    	{
    		String text = "";
     
    		public OnTextData(String text)
    		{
    			this.text = text;
    		}
    	}
     
    	class PublishThread extends Thread
    	{
    		private boolean running = true;
    		private Object lock = new Object();
    		private int interval = 500;
    		private int publishInterval = 1000;
    		private long lastSend = -1;
    		private IApplicationInstance appInstance = null;
    		private IMediaStream stream = null;
    		private int count = 0;
     
    		public void doStop()
    		{
    			synchronized(lock)
    			{
    				this.running = false;
    			}
    		}
     
    		public PublishThread(IApplicationInstance appInstance, IMediaStream stream)
    		{
    			this.appInstance = appInstance;
    			this.stream = stream;
    		}
     
    		public void run()
    		{
    			getLogger().info("ModulePublishOnTextData#PublishThread.run["+stream.getContextStr()+"]: START");
     
    			int index = 0;
     
    			while(true)
    			{
    				try
    				{
    					long currTime = System.currentTimeMillis();
    					if (lastSend < 0 || (currTime - lastSend) > publishInterval)
    					{
    						lastSend = currTime;
     
    						while(true)
    						{
    							if (onTextDataList.size() <= 0)
    								break;
     
    							OnTextData onTextData = onTextDataList.get(index%onTextDataList.size());
    							index++;
     
    							if (onTextData == null)
    								break;
     
    							sendTextDataMessage(stream, onTextData);
    							break;
    						}
    					}
     
    					Thread.sleep(interval);
    				}
    				catch(Exception e)
    				{
    					getLogger().error("ModulePublishOnTextData#PublishThread.run["+stream.getContextStr()+"]: "+e.toString());
    				}
     
    				synchronized(lock)
    				{
    					if (!running)
    						break;
    				}
    			}
    			getLogger().info("ModulePublishOnTextData#PublishThread.run["+stream.getContextStr()+"]: STOP");
    		}
     
    		public void sendTextDataMessage(IMediaStream stream, OnTextData onTextData)
    		{
    			try
    			{
    				AMFDataObj amfData = new AMFDataObj();
     
    				//System.out.println("Text: "+count);
     
    				//debug  amfData.put("text", new AMFDataItem("T: "+(count++)));
    				amfData.put("text", new AMFDataItem(onTextData.text));
    				amfData.put("language", new AMFDataItem(languageID));
    				amfData.put("trackid", new AMFDataItem(trackNumber));							
    				stream.sendDirect("onTextData", amfData);
    				((MediaStream)stream).processSendDirectMessages();	
     
     
     
    			}
    			catch(Exception e)
    			{
    				getLogger().error("ModulePublishOnTextData#PublishThread.sendTextDataMessage["+stream.getContextStr()+"]: "+e.toString());
    				e.printStackTrace();
    			}
    		}
     
    		public int getPublishInterval()
    		{
    			return publishInterval;
    		}
     
    		public void setPublishInterval(int publishInterval)
    		{
    			this.publishInterval = publishInterval;
    		}
    	}
     
    	public class MyMediaStreamListener implements IMediaStreamActionNotify3
    	{
    		private PublishThread publishThread = null;
     
    		public void onPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend)
    		{
    			IApplicationInstance appInstance = stream.getStreams().getAppInstance();
     
    			if (!stream.isTranscodeResult())
    			{
    				publishThread = new PublishThread(appInstance, stream);
    				publishThread.setName("OnTextDataPublisher-"+appInstance.getContextStr()+"-"+streamName);
    				publishThread.setDaemon(true);
    				publishThread.setPublishInterval(publishInterval);
    				publishThread.start();
    			}
    		}
     
    		public void onUnPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend)
    		{
    			if (publishThread != null)
    				publishThread.doStop();
    			publishThread = null;
    		}
     
    		public void onMetaData(IMediaStream stream, AMFPacket metaDataPacket)
    		{
    		}
     
    		public void onPauseRaw(IMediaStream stream, boolean isPause, double location)
    		{
    		}
     
    		public void onPause(IMediaStream stream, boolean isPause, double location)
    		{
    		}
     
    		public void onPlay(IMediaStream stream, String streamName, double playStart, double playLen, int playReset)
    		{
    		}
     
    		public void onSeek(IMediaStream stream, double location)
    		{
    		}
     
    		public void onStop(IMediaStream stream)
    		{
    		}
     
    		public void onCodecInfoVideo(IMediaStream stream, MediaCodecInfoVideo codecInfoVideo)
    		{
    		}
     
    		public void onCodecInfoAudio(IMediaStream stream, MediaCodecInfoAudio codecInfoAudio)
    		{
    		}
    	}
     
    	private List<OnTextData> onTextDataList = new ArrayList<OnTextData>();
    	private boolean charsetTest = false;
    	private String languageID = "eng";
    	private int trackNumber = 99;
    	//private final Charset UTF8_CHARSET = Charset.forName("UTF-8"); 
    	private int publishInterval = 1000;
     
    	public void onAppStart(IApplicationInstance appInstance)
    	{
    		getLogger().info("ModulePublishOnTextData.onAppStart["+appInstance.getContextStr()+"]");
     
    		String onTextDataFile = "${com.wowza.wms.context.VHostConfigHome}/content/ontextdata.txt";
     
    		publishInterval = appInstance.getProperties().getPropertyInt("publishOnTextDataPublishInterval", publishInterval);
    		onTextDataFile = appInstance.getProperties().getPropertyStr("publishOnTextDataFile", onTextDataFile);
    		languageID = appInstance.getProperties().getPropertyStr("publishOnTextDataLanguageID", languageID);
    		trackNumber = appInstance.getProperties().getPropertyInt("publishOnTextDataTrackNumber", trackNumber);
     
    		charsetTest = appInstance.getProperties().getPropertyBoolean("publishOnTextCharsetTest", charsetTest);
     
    		Map<String, String> pathMap = new HashMap<String, String>();
    		pathMap.put("com.wowza.wms.context.VHost", appInstance.getVHost().getName());
    		pathMap.put("com.wowza.wms.context.VHostConfigHome", appInstance.getVHost().getHomePath());
    		pathMap.put("com.wowza.wms.context.Application", appInstance.getApplication().getName());
    		pathMap.put("com.wowza.wms.context.ApplicationInstance", appInstance.getName());
     
    		onTextDataFile =  SystemUtils.expandEnvironmentVariables(onTextDataFile, pathMap);
     
    		File file = new File(onTextDataFile);
     
    		getLogger().info("ModulePublishOnTextData.onAppStart["+appInstance.getContextStr()+"]: sendInterval: "+publishInterval);
     
    		if (charsetTest)
    		{
    			int charCode = 0x20;
    			int lastChar = 0x100;
    			int charsPerLine = 20;
     
    			while(true)
    			{
    				int charsToPublish = lastChar-charCode;
    				if (charsToPublish > charsPerLine)
    					charsToPublish = charsPerLine;
     
    				String bytesStr = "";
    				for(int i=0;i<charsToPublish;i++)
    				{
    					int thisChar = charCode+i;
     
    					// map unicode codepoint to utf-8
    					int myChar = 0;
    					if (thisChar >= 0x020 && thisChar < 0x080)
    						myChar = (int)thisChar;
    					else if (thisChar >= 0x080 && thisChar < 0x0C0)
    						myChar = (int)(0x0c280 + (thisChar - 0x080));
    					else if (thisChar >= 0x0C0 && thisChar < 0x100)
    						myChar = (int)(0x0c380 + (thisChar - 0x0C0));
     
    					try
    					{
    						bytesStr += new String(BufferUtils.intToByteArray(myChar, (myChar<0x080?1:2)), "UTF-8");
    					}
    					catch(Exception e)
    					{
    					}
    				}
     
    				bytesStr = "0x"+Integer.toHexString(charCode)+":"+bytesStr+":";
     
    				onTextDataList.add(new OnTextData(bytesStr));
     
    				charCode += charsToPublish;
     
    				if (charCode >= lastChar)
    					break;
    			}
    		}
    		else
    		{
    			getLogger().info("ModulePublishOnTextData.onAppStart["+appInstance.getContextStr()+"]: onTextDataFile[exists:"+file.exists()+"]: "+onTextDataFile);
     
    			BufferedReader inf = null;
    			if (file.exists())
    			{
    				try
    				{
    					inf = new BufferedReader(new FileReader(file));
    					String line;
    					while ((line = inf.readLine()) != null)
    					{
    						line = line.trim();
    						if (line.startsWith("#"))
    							continue;
    						if (line.length() == 0)
    							continue;
     
    						onTextDataList.add(new OnTextData(line));
     
    					}
    				}
    				catch(Exception e)
    				{
    					getLogger().error("ModulePublishOnTextData.onAppStart[read]: "+ e.toString());
    				}
    			}
     
    			getLogger().info("ModulePublishOnTextData.onAppStart["+appInstance.getContextStr()+"]: onTextDataFileCount: "+onTextDataList.size());
     
    			try
    			{
    				if (inf != null)
    					inf.close();
    				inf = null;	
    			}
    			catch(Exception e)
    			{
    				getLogger().error("ModulePublishOnTextData.onAppStart[close]: "+ e.toString());
    			}
    		}
    	}
     
    	public void onStreamCreate(IMediaStream stream)
    	{
    		stream.addClientListener(new MyMediaStreamListener());
    	}
    }
    Et donc à la place du texte je souhaiterais l'heure GMT ou une chaine en retour d'un appel http.

    Merci pour ton attention

  6. #6
    Expert éminent
    Avatar de fred1599
    Homme Profil pro
    Lead Dev Python
    Inscrit en
    Juillet 2006
    Messages
    3 823
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Lead Dev Python
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Juillet 2006
    Messages : 3 823
    Points : 7 119
    Points
    7 119
    Par défaut
    Ok, pour cela tu dois,


    • récupérer la chaîne de caractères représentant l'heure GMT
    • l'écrire avec la méthode write de l'objet BufferedWriter


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    FileWriter fstream = new FileWriter(fileName, true);
    BufferedWriter out = new BufferedWriter(fstream);
    où filename est le nom du fichier où tu vas écrire

    Pour récupérer l'heure GMT, tu peux regarder cet exemple

    Dans tous les cas, je pense qu'il te faudra un minimum d'investissement

    EDIT: J'avais pas vu pour le flux vidéo, là par contre je connais pas, ça fait que 4 jours que je fais du java...
    Celui qui trouve sans chercher est celui qui a longtemps cherché sans trouver.(Bachelard)
    La connaissance s'acquiert par l'expérience, tout le reste n'est que de l'information.(Einstein)

  7. #7
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    201
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 201
    Points : 150
    Points
    150
    Par défaut
    Merci pour tes contributions.

    Je regarde pour l'heure.

Discussions similaires

  1. Injecter une date dans mysql par Date Picker
    Par larsvangeil dans le forum Général JavaScript
    Réponses: 44
    Dernier message: 19/07/2012, 23h23
  2. Convertir une date GMT en date locale
    Par olibara dans le forum C#
    Réponses: 3
    Dernier message: 01/12/2008, 23h48
  3. [SQL][Timestamp] obtenir une date GMT
    Par JeffK dans le forum Oracle
    Réponses: 9
    Dernier message: 20/07/2006, 17h26
  4. DateTimePicker lui injecter une date ?
    Par gsmdu62 dans le forum Delphi
    Réponses: 3
    Dernier message: 24/05/2006, 10h03
  5. []Comment convertir une date GMT en date vb ?
    Par Invité dans le forum VB 6 et antérieur
    Réponses: 10
    Dernier message: 11/08/2004, 16h01

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo